简体   繁体   English

Android多图像上传无法将数据发送到服务器

[英]Android Multiple image upload not send data to server

Hello I am working with android . 您好,我正在使用android。 I want to send a multipart data to asp.net server which contains a text and mulltiple images. 我想将包含文本和多重图像的多部分数据发送到asp.net服务器。 I can able to send only one image to send to server. 我只能发送一个图像发送到服务器。 I used this code 我用了这段代码

for(int i=0;i<Captured_imagePath.size();i++)
                {

                    File file2 = new File("my folder path" + Captured_imagePath.get(i));


                    entityBuilder.addBinaryBody(file2.getName(), file2, ContentType.create("image/jpeg"), Captured_imagePath.get(i));

                    entityBuilder.setBoundary(boundary);


                }

where Captured_imagePath is array list of image names in the folder.I tried to print the sending data to a file and it works fine in the case when I send only one image, if I used more than one image, means if Captured_imagePath has size >1 it will not print the sending data and image not send to server.Is there any problem with my code ? 其中Captured_imagePath是文件夹中图像名称的数组列表。我尝试将发送的数据打印到文件中,并且在仅发送一幅图像的情况下,如果使用了多幅图像,则可以正常工作,这意味着Captured_imagePath的大小> 1它不会打印发送数据并且图像不会发送到服务器。我的代码是否有问题? I stucked with this problem. 我坚持这个问题。 Please help me Thanks in advance :) 请帮助我在此先感谢:)

you can try this 你可以试试这个

   `   
for ( int i= 0; i < size ; i++ ){

    try {
    File file = new File("my folder path" + Captured_imagePath.get(i));

    InputStreamEntity reqEntity = new InputStreamEntity(
            new FileInputStream(file), -1);
    reqEntity.setContentType("binary/octet-stream");
    reqEntity.setChunked(true); //to send in multiparts
    httppost.setEntity(reqEntity) ;
    httpClient.execute(httppost); // can catch httpResponse here
    } catch ( Exception e ) { e.printStacktrace() ; }
    }`

where file is File var. 其中file是File var。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM