如何使用点击上传按钮来上传具体名单形象 [英] How to upload specific List image using click on Upload button

查看:230
本文介绍了如何使用点击上传按钮来上传具体名单形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何到特定的图像上传到服务器,每当用户不要点击上传按钮在列表视图项行

使用以下行来显示特定图像名称对话框中,每当用户不要点击上传按钮:

 文件名= ImageList.get(位置)的ToString()子(strPath.lastIndexOf('/')+ 1,strPath.length());

OldUploadActivity.java:

  // btnUpload
            btnUpload =(按钮)convertView.findViewById(R.id.btnUpload);
            btnUpload.setTextColor(Color.BLACK);
            btnUpload.setTag(strPath的);
            btnUpload.setOnClickListener(新View.OnClickListener(){
            @燮pressWarnings(德precation)
            公共无效的onClick(视图v){
                //上传                文件名= ImageList.get(位置)的ToString()子(strPath.lastIndexOf('/')+ 1,strPath.length());                }
            });    //上传
    公共无效startUpload(最终诠释位置){
        可运行可运行=新的Runnable(){            公共无效的run(){
                handler.post(新的Runnable(){
                    公共无效的run(){
                        视图V = lstView.getChildAt(位置 - lstView.getFirstVisiblePosition());
                        //显示进度
                        进度进度=(进度)v.findViewById(R.id.progressBar);
                        progress.setVisibility(View.VISIBLE);                        // 状态
                        TextView的状态=(TextView中)v.findViewById(R.id.C​​olStatus);
                        status.setText(上传..);                        新UploadFileAsync()执行(将String.valueOf(位置));
                    }
                });
            }
        };
        新的线程(可运行)。开始();
    }
    //异步上传
    公共类UploadFileAsync扩展的AsyncTask<弦乐,太虚,太虚> {        串resServer;
        INT位置;        在preExecute保护无效(){            super.on preExecute();
        }        @覆盖
        保护无效doInBackground(字符串... PARAMS){
            // TODO自动生成方法存根            INT位置;            位置=的Integer.parseInt(PARAMS [0]);
            Log.d(位置::,+位置);            INT读取动作,方bytesAvailable,缓冲区大小;
            字节[]缓冲区;
            INT MAXBUFFERSIZE = 1 * 1024 * 1024;
            中期业绩code = 0;
            串resMessage =;            字符串lineEnd =\\ r \\ n;
            串twoHyphens = - ;
            字符串边界=*****;
            串strSDPath;            // 文件路径
            strSDPath = ImageList.get(位置)的ToString();            //上传到PHP脚本
            字符串strUrlServer =htt​​p://10.0.2.2/res/files.php;            尝试{
                / **检查SD卡文件*** /
                档案文件=新的文件(strSDPath);
                如果(!file.exists())
                {
                    resServer ={\\StatusID \\:\\0 \\,\\错误\\:\\请检查SD卡\\路径};
                    返回null;
                }                的FileInputStream的FileInputStream =新的FileInputStream(新文件(strSDPath));                网址URL =新的URL(strUrlServer);
                HttpURLConnection的康恩=(HttpURLConnection类)url.openConnection();
                conn.setDoInput(真);
                conn.setDoOutput(真);
                conn.setUseCaches(假);
                conn.setRequestMethod(POST);                conn.setRequestProperty(连接,保持活动);
                conn.setRequestProperty(内容类型,
                        的multipart / form-data的;边界=+边界);                DataOutputStream类的OutputStream =新的DataOutputStream类(康恩
                        .getOutputStream());
                outputStream.writeBytes(twoHyphens +边界+ lineEnd);
                的OutputStream
                .writeBytes(内容处置:表格数据;名称= \\filUpload \\;文件名= \\
                        + strSDPath +\\+ lineEnd);
                outputStream.writeBytes(lineEnd);                参考bytesAvailable = fileInputStream.available();
                BUFFERSIZE = Math.min(方bytesAvailable,MAXBUFFERSIZE);
                缓冲区=新的字节[缓冲区大小]                //读取文件
                读取动作= fileInputStream.read(缓冲液,0,缓冲区大小);                而(读取动作大于0){
                    outputStream.write(缓冲液,0,缓冲区大小);
                    参考bytesAvailable = fileInputStream.available();
                    BUFFERSIZE = Math.min(方bytesAvailable,MAXBUFFERSIZE);
                    读取动作= fileInputStream.read(缓冲液,0,缓冲区大小);
                }                outputStream.writeBytes(lineEnd);
                outputStream.writeBytes(twoHyphens +边界+ twoHyphens + lineEnd);                //响应code和留言
                RES code = conn.getResponse code();
                如果(RES code == HttpURLConnection.HTTP_OK)
                {
                    InputStream为= conn.getInputStream();
                    ByteArrayOutputStream BOS =新ByteArrayOutputStream();                    INT读= 0;
                    而((读= is.​​read())!= -1){
                        bos.write(读);
                    }
                    字节[]结果= bos.toByteArray();
                    bos.close();                    resMessage =新的字符串(结果);
                }                Log.d(RES code =,Integer.toString(RES code));
                Log.d(resMessage =,resMessage.toString());                fileInputStream.close();
                outputStream.flush();
                outputStream.close();                resServer = resMessage.toString();            }赶上(例外前){
                // 异常处理
                返回null;
            }
            返回null;
        }        保护无效onPostExecute(虚空未使用){
            statusWhenFinish(位置,resServer);
        }
    }    //当上传完成
    保护无效statusWhenFinish(INT位置,弦乐resServer){        视图V = lstView.getChildAt(位置 - lstView.getFirstVisiblePosition());        //显示进度
        进度进度=(进度)v.findViewById(R.id.progressBar);
        progress.setVisibility(View.GONE);        // 状态
        TextView的状态=(TextView中)v.findViewById(R.id.C​​olStatus);
        /*** 默认值 ***/
        串strStatusID =0;
        字符串strMessage =未知状态!;        尝试{
            JSONObject的C =新的JSONObject(resServer);
            strStatusID = c.getString(StatusID);
            strMessage = c.getString(信息);
        }赶上(JSONException E){
            // TODO自动生成catch块
            e.printStackTrace();
        }        // prepare状态
        如果(strStatusID.equals(0))
        {
            //当更新失败
            status.setText(strMessage);
            status.setTextColor(Color.RED);            再次启用//按钮
            按钮btnUpload =(按钮)v.findViewById(R.id.btnUpload);
            btnUpload.setText(已上传);
            btnUpload.setTextColor(Color.RED);
            btnUpload.setEnabled(真);
        }
        其他
        {
            status.setText(上传完成);
            status.setTextColor(Color.GREEN);
        }
    }

activity_column.xml:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>< ImageView的
机器人:ID =@ + ID / ColImgPath
机器人:layout_width =110dp
机器人:layout_height =110dp
/><进度
机器人:ID =@ + ID /进度
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>< TableLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT><的TableRow
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的TextView
机器人:ID =@ + ID / ColImgName
机器人:文字=1列/>
< /&的TableRow GT;<的TableRow
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT><的TextView
机器人:ID =@ + ID / ColStatus
机器人:textAppearance =机器人:ATTR / textAppearanceSmall
机器人:文字=状态/>< /&的TableRow GT;<的TableRow
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT><按钮
机器人:ID =@ + ID / btnUpload
风格=机器人:ATTR / buttonStyleSmall
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=上传/><按钮
机器人:ID =@ + ID / btnPrint
风格=机器人:ATTR / buttonStyleSmall
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=打印/>
< /&的TableRow GT;< / TableLayout>< / LinearLayout中>


解决方案

试试这个code:

  btnUpload =(按钮)convertView.findViewById(R.id.btnUpload);
        btnUpload.setTextColor(Color.BLACK);
        btnUpload.setTag(strPath的);
        btnUpload.setOnClickListener(新View.OnClickListener(){
        @燮pressWarnings(德precation)
        公共无效的onClick(视图v){
            //上传             startUpload(位置);
             文件名= ImageList.get(位置)的ToString()
            .substring(strPath.lastIndexOf('/')+ 1,strPath.length());            }
        });//上传
公共无效startUpload(最终诠释位置){
    可运行可运行=新的Runnable(){        公共无效的run(){
            handler.post(新的Runnable(){
                公共无效的run(){
                    视图V = lstView.getChildAt(位置 - lstView.getFirstVisiblePosition());
                    //显示进度
                    进度进度=(进度)v.findViewById(R.id.progressBar);
                    progress.setVisibility(View.VISIBLE);                    // 状态
                    TextView的状态=(TextView中)v.findViewById(R.id.C​​olStatus);
                    status.setText(上传..);                    新UploadFileAsync()执行(将String.valueOf(位置));
                }
            });
        }
    };
    新的线程(可运行)。开始();
}
//异步上传
公共类UploadFileAsync扩展的AsyncTask<弦乐,太虚,太虚> {    串resServer;
    INT位置;    在preExecute保护无效(){        super.on preExecute();
    }    @覆盖
    保护无效doInBackground(字符串... PARAMS){
        // TODO自动生成方法存根        INT位置;        位置=的Integer.parseInt(PARAMS [0]);
        Log.d(位置::,+位置);        INT读取动作,方bytesAvailable,缓冲区大小;
        字节[]缓冲区;
        INT MAXBUFFERSIZE = 1 * 1024 * 1024;
        中期业绩code = 0;
        串resMessage =;        字符串lineEnd =\\ r \\ n;
        串twoHyphens = - ;
        字符串边界=*****;
        串strSDPath;        // 文件路径
        strSDPath = ImageList.get(位置)的ToString();        //上传到PHP脚本
        字符串strUrlServer =htt​​p://10.0.2.2/res/files.php;        尝试{
            / **检查SD卡文件*** /
            档案文件=新的文件(strSDPath);
            如果(!file.exists())
            {
                resServer ={\\StatusID \\:\\0 \\,\\错误\\:\\请检查SD卡\\路径};
                返回null;
            }            的FileInputStream的FileInputStream =新的FileInputStream(新文件(strSDPath));            网址URL =新的URL(strUrlServer);
            HttpURLConnection的康恩=(HttpURLConnection类)url.openConnection();
            conn.setDoInput(真);
            conn.setDoOutput(真);
            conn.setUseCaches(假);
            conn.setRequestMethod(POST);            conn.setRequestProperty(连接,保持活动);
            conn.setRequestProperty(内容类型,
                    的multipart / form-data的;边界=+边界);            DataOutputStream类的OutputStream =新的DataOutputStream类(康恩
                    .getOutputStream());
            outputStream.writeBytes(twoHyphens +边界+ lineEnd);
            的OutputStream
            .writeBytes(内容处置:表格数据;名称= \\filUpload \\;文件名= \\
                    + strSDPath +\\+ lineEnd);
            outputStream.writeBytes(lineEnd);            参考bytesAvailable = fileInputStream.available();
            BUFFERSIZE = Math.min(方bytesAvailable,MAXBUFFERSIZE);
            缓冲区=新的字节[缓冲区大小]            //读取文件
            读取动作= fileInputStream.read(缓冲液,0,缓冲区大小);            而(读取动作大于0){
                outputStream.write(缓冲液,0,缓冲区大小);
                参考bytesAvailable = fileInputStream.available();
                BUFFERSIZE = Math.min(方bytesAvailable,MAXBUFFERSIZE);
                读取动作= fileInputStream.read(缓冲液,0,缓冲区大小);
            }            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(twoHyphens +边界+ twoHyphens + lineEnd);            //响应code和留言
            RES code = conn.getResponse code();
            如果(RES code == HttpURLConnection.HTTP_OK)
            {
                InputStream为= conn.getInputStream();
                ByteArrayOutputStream BOS =新ByteArrayOutputStream();                INT读= 0;
                而((读= is.​​read())!= -1){
                    bos.write(读);
                }
                字节[]结果= bos.toByteArray();
                bos.close();                resMessage =新的字符串(结果);
            }            Log.d(RES code =,Integer.toString(RES code));
            Log.d(resMessage =,resMessage.toString());            fileInputStream.close();
            outputStream.flush();
            outputStream.close();            resServer = resMessage.toString();        }赶上(例外前){
            // 异常处理
            返回null;
        }
        返回null;
    }    保护无效onPostExecute(虚空未使用){
        statusWhenFinish(位置,resServer);
    }
}

How to upload specific image to server, whenever user do click on Upload button in a List View Item Row

Using below line to show specific Image Name in Dialog Box, whenever user do click on Upload button:

 fileName=ImageList.get(position).toString().substring(strPath.lastIndexOf('/')+1, strPath.length());

OldUploadActivity.java:

            //  btnUpload
            btnUpload = (Button) convertView.findViewById(R.id.btnUpload);
            btnUpload.setTextColor(Color.BLACK);
            btnUpload.setTag(strPath);
            btnUpload.setOnClickListener(new View.OnClickListener() {


            @SuppressWarnings("deprecation")
            public void onClick(View v) {                   
                // Upload

                fileName=ImageList.get(position).toString().substring(strPath.lastIndexOf('/')+1, strPath.length());

                }
            });     



    //Upload
    public void startUpload(final int position) {      
        Runnable runnable = new Runnable() {

            public void run() {
                handler.post(new Runnable() {
                    public void run() {
                        View v = lstView.getChildAt(position - lstView.getFirstVisiblePosition());
                        // Show ProgressBar
                        ProgressBar progress = (ProgressBar)v.findViewById(R.id.progressBar);
                        progress.setVisibility(View.VISIBLE);

                        //  Status  
                        TextView status = (TextView)v.findViewById(R.id.ColStatus);
                        status.setText("Uploading..");

                        new UploadFileAsync().execute(String.valueOf(position));   
                    }
                }); 
            }
        };
        new Thread(runnable).start();
    }


    // Async Upload
    public class UploadFileAsync extends AsyncTask<String, Void, Void> {

        String resServer;
        int position;           

        protected void onPreExecute() {

            super.onPreExecute();               
        }

        @Override
        protected Void doInBackground(String... params) {
            //  TODO Auto-generated method stub

            int position;

            position = Integer.parseInt(params[0]);
            Log.d("position::", " " + position);

            int bytesRead, bytesAvailable, bufferSize;
            byte[] buffer;
            int maxBufferSize = 1 * 1024 * 1024;
            int resCode = 0;
            String resMessage = "";

            String lineEnd = "\r\n";
            String twoHyphens = "--";
            String boundary =  "*****";
            String strSDPath;

            //  File Path
            strSDPath = ImageList.get(position).toString();

            // Upload to PHP Script
            String strUrlServer = "http://10.0.2.2/res/files.php";              

            try {
                /** Check file on SD Card ***/
                File file = new File(strSDPath);
                if(!file.exists())
                {
                    resServer = "{\"StatusID\":\"0\",\"Error\":\"Please check path on SD Card\"}";
                    return null;
                }

                FileInputStream fileInputStream = new FileInputStream(new File(strSDPath));

                URL url = new URL(strUrlServer);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setDoInput(true);  
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestMethod("POST");

                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("Content-Type",
                        "multipart/form-data;boundary=" + boundary);

                DataOutputStream outputStream = new DataOutputStream(conn
                        .getOutputStream());
                outputStream.writeBytes(twoHyphens + boundary + lineEnd);
                outputStream
                .writeBytes("Content-Disposition: form-data; name=\"filUpload\";filename=\""
                        + strSDPath + "\"" + lineEnd);
                outputStream.writeBytes(lineEnd);

                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                buffer = new byte[bufferSize];

                // Read file
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);

                while (bytesRead > 0) {
                    outputStream.write(buffer, 0, bufferSize);
                    bytesAvailable = fileInputStream.available();
                    bufferSize = Math.min(bytesAvailable, maxBufferSize);
                    bytesRead = fileInputStream.read(buffer, 0, bufferSize);
                }

                outputStream.writeBytes(lineEnd);
                outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

                // Response Code and  Message
                resCode = conn.getResponseCode();
                if(resCode == HttpURLConnection.HTTP_OK)
                {
                    InputStream is = conn.getInputStream();
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();

                    int read = 0;
                    while ((read = is.read()) != -1) {
                        bos.write(read);
                    }
                    byte[] result = bos.toByteArray();
                    bos.close();

                    resMessage = new String(result);
                }

                Log.d("resCode=",Integer.toString(resCode));
                Log.d("resMessage=",resMessage.toString());

                fileInputStream.close();
                outputStream.flush();
                outputStream.close();

                resServer = resMessage.toString();

            } catch (Exception ex) {
                // Exception handling
                return null;
            }
            return null;
        }

        protected void onPostExecute(Void unused) {
            statusWhenFinish(position,resServer);
        }
    }

    // when upload finish
    protected void statusWhenFinish(int position, String resServer) {

        View v = lstView.getChildAt(position - lstView.getFirstVisiblePosition());

        // Show ProgressBar
        ProgressBar progress = (ProgressBar)v.findViewById(R.id.progressBar);
        progress.setVisibility(View.GONE);

        // Status
        TextView status = (TextView)v.findViewById(R.id.ColStatus);
        /*** Default Value ***/
        String strStatusID = "0";
        String strMessage = "Unknow Status!";

        try {      
            JSONObject c = new JSONObject(resServer);
            strStatusID = c.getString("StatusID");
            strMessage = c.getString("Message");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // Prepare Status       
        if(strStatusID.equals("0"))
        {
            // When update Failed
            status.setText( strMessage );
            status.setTextColor(Color.RED);

            // Enabled Button again
            Button btnUpload = (Button) v.findViewById(R.id.btnUpload);
            btnUpload.setText("Already Uploaded");
            btnUpload.setTextColor(Color.RED);
            btnUpload.setEnabled(true);
        }
        else
        {
            status.setText("Upload Completed");
            status.setTextColor(Color.GREEN);
        }
    }

activity_column.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView
android:id="@+id/ColImgPath"
android:layout_width="110dp"
android:layout_height="110dp"
/>

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TableLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/ColImgName"
android:text="Column 1" />


</TableRow>

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:id="@+id/ColStatus"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Status" />

</TableRow>

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<Button
android:id="@+id/btnUpload"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload" />

<Button
android:id="@+id/btnPrint"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Print" />


</TableRow>

</TableLayout>

</LinearLayout>

解决方案

Try this code:

        btnUpload = (Button) convertView.findViewById(R.id.btnUpload);
        btnUpload.setTextColor(Color.BLACK);
        btnUpload.setTag(strPath);
        btnUpload.setOnClickListener(new View.OnClickListener() {


        @SuppressWarnings("deprecation")
        public void onClick(View v) {                   
            // Upload

             startUpload(position);
             fileName=ImageList.get(position).toString()
            .substring(strPath.lastIndexOf('/')+1, strPath.length());

            }
        });     



//Upload
public void startUpload(final int position) {      
    Runnable runnable = new Runnable() {

        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    View v = lstView.getChildAt(position - lstView.getFirstVisiblePosition());
                    // Show ProgressBar
                    ProgressBar progress = (ProgressBar)v.findViewById(R.id.progressBar);
                    progress.setVisibility(View.VISIBLE);

                    //  Status  
                    TextView status = (TextView)v.findViewById(R.id.ColStatus);
                    status.setText("Uploading..");

                    new UploadFileAsync().execute(String.valueOf(position));   
                }
            }); 
        }
    };
    new Thread(runnable).start();
}


// Async Upload
public class UploadFileAsync extends AsyncTask<String, Void, Void> {

    String resServer;
    int position;           

    protected void onPreExecute() {

        super.onPreExecute();               
    }

    @Override
    protected Void doInBackground(String... params) {
        //  TODO Auto-generated method stub

        int position;

        position = Integer.parseInt(params[0]);
        Log.d("position::", " " + position);

        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = 1 * 1024 * 1024;
        int resCode = 0;
        String resMessage = "";

        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary =  "*****";
        String strSDPath;

        //  File Path
        strSDPath = ImageList.get(position).toString();

        // Upload to PHP Script
        String strUrlServer = "http://10.0.2.2/res/files.php";              

        try {
            /** Check file on SD Card ***/
            File file = new File(strSDPath);
            if(!file.exists())
            {
                resServer = "{\"StatusID\":\"0\",\"Error\":\"Please check path on SD Card\"}";
                return null;
            }

            FileInputStream fileInputStream = new FileInputStream(new File(strSDPath));

            URL url = new URL(strUrlServer);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);  
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");

            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Content-Type",
                    "multipart/form-data;boundary=" + boundary);

            DataOutputStream outputStream = new DataOutputStream(conn
                    .getOutputStream());
            outputStream.writeBytes(twoHyphens + boundary + lineEnd);
            outputStream
            .writeBytes("Content-Disposition: form-data; name=\"filUpload\";filename=\""
                    + strSDPath + "\"" + lineEnd);
            outputStream.writeBytes(lineEnd);

            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            buffer = new byte[bufferSize];

            // Read file
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);

            while (bytesRead > 0) {
                outputStream.write(buffer, 0, bufferSize);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            }

            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

            // Response Code and  Message
            resCode = conn.getResponseCode();
            if(resCode == HttpURLConnection.HTTP_OK)
            {
                InputStream is = conn.getInputStream();
                ByteArrayOutputStream bos = new ByteArrayOutputStream();

                int read = 0;
                while ((read = is.read()) != -1) {
                    bos.write(read);
                }
                byte[] result = bos.toByteArray();
                bos.close();

                resMessage = new String(result);
            }

            Log.d("resCode=",Integer.toString(resCode));
            Log.d("resMessage=",resMessage.toString());

            fileInputStream.close();
            outputStream.flush();
            outputStream.close();

            resServer = resMessage.toString();

        } catch (Exception ex) {
            // Exception handling
            return null;
        }
        return null;
    }

    protected void onPostExecute(Void unused) {
        statusWhenFinish(position,resServer);
    }
}   

这篇关于如何使用点击上传按钮来上传具体名单形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆