阅读背景:

从SD卡中选择多个图像并将其上载到服务器

来源:互联网 

My code:

protected String doInBackground(HttpResponse... arg0)
{
    String result = "";         
    File file = new File(selectImages);
    try {
        HttpClient client = new DefaultHttpClient();
        String postURL = "https://192.168.1.11/api/review/add_image.php?";
        post = new HttpPost(postURL); 
        FileBody bin = new FileBody(file);
        totalSize = bin.getContentLength();
        MultiPartEntity reqEntity = new MultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, new ProgressListener()
        {
            public void transferred(long num)
            {
                publishProgress((int) ((num / (float) totalSize) * 100));
            }
        });

        reqEntity.addPart("userfile", bin);
        post.setEntity(reqEntity); 
        HttpResponse response = client.execute(post);
        HttpEntity resEntity = response.getEntity();  
        if (resEntity != null) {    
            result = EntityUtils.toString(resEntity);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
protected String doInBackground(Http



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: