使用SOAP Web服务上载大文件

时间:2013-06-16 16:50:16

标签: android web-services file-upload out-of-memory android-ksoap2

我需要上传一份10-100mb的文件。当我尝试上传文件时,它会在行

中给出outofmemory错误
sb.append(Base64.encode(data));

我该如何解决这个问题?我的Web服务是SOAP Web服务。这是该方法的完整代码。

 public static String fileToBase64(String path) throws IOException {
            File imagefile = new File(path);
            byte[] data = new byte[3000];
            FileInputStream fin = null;
            StringBuffer sb = new StringBuffer();
            try {
                fin = new FileInputStream(imagefile);
                while(fin.read(data) >= 0) {
                   sb.append(Base64.encode(data));
               }
                return sb.toString();
            } catch (Exception e) {
                // TODO: handle exception
            } finally{
                fin.close();
            }
            return null;
        }

1 个答案:

答案 0 :(得分:0)

我看到两种方法:

  1. 使用流式XML编写器和分块内容来避免过多的内存消耗。不确定它是否适用于此。

  2. 使用MTOM发送带附件的SOAP消息。

  3. 此方法更可取,但您必须向Web服务添加所需的功能。