【问题标题】:Android Multiple image upload not send data to serverAndroid 多张图片上传不向服务器发送数据
【发布时间】:2016-04-27 06:31:46
【问题描述】:

您好,我正在使用 android 。我想将多部分数据发送到包含文本和多个图像的 asp.net 服务器。我只能发送一张图片发送到服务器。我用了这段代码

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);


                }

其中 Captured_imagePath 是文件夹中图像名称的数组列表。我尝试将发送数据打印到文件中,并且在我只发送一张图像的情况下它工作正常,如果我使用多张图像,则意味着 Captured_imagePath大小 >1 它不会打印发送数据和图像不会发送到服务器。我的代码有问题吗?我坚持这个问题。请帮助我提前谢谢:)

【问题讨论】:

标签: java android image upload multipart


【解决方案1】:

你可以试试这个

   `   
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() ; }
    }`

file 是 File var。

【讨论】:

  • 这将发送 http 请求作为数组大小的时间。对吗?
  • 可以,前提是您正确构建了 httpClient。
猜你喜欢
  • 2013-01-12
  • 2019-03-07
  • 2015-10-04
  • 2014-05-31
  • 1970-01-01
  • 2012-03-11
  • 1970-01-01
  • 2017-10-25
  • 2023-03-11
相关资源
最近更新 更多