通过帖子和水平进度对话框上传图像

时间:2014-07-13 05:59:43

标签: android file-upload image-uploading android-progressbar android-volley

我想通过post方法上传多个图片和json。我不想使用BASE 64方法,因为它比通过文件上传的图片上传重37%。

我使用下面的代码进行上传。

public void doFileUpload(ArrayList<UploadImage> images){
        try {
            MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
            entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(link);
            //MultipartEntity reqEntity = new MultipartEntity();
            for(UploadImage img : images){
                FileBody bin1 = new FileBody(img.getImageFile());

                entityBuilder.addPart("uploaded_file", bin1);
            }
            post.setEntity(entityBuilder.build());
            HttpResponse response = client.execute(post);

            HttpEntity resEntity = response.getEntity();

            final String response_str = EntityUtils.toString(resEntity);

            Log.e("Response", response_str);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

我还希望显示水平进度对话框,其中包含上传图像的数量。我做过R&amp; D为此并找到this link.但是,这里无法上传多张图片,也显示horizontal progress dialog有进展。

我使用volley library使用json上传图片。

还有其他最佳方法可以将多张图片上传到服务器吗?

由于

0 个答案:

没有答案
相关问题