简体   繁体   English

使用SOAP Web服务上传大文件

[英]Upload large file using SOAP web service

I need to upload a file which is vary from 10-100mb. 我需要上传一个10-100mb不等的文件。 When I try to upload the file, it gives me outofmemory error in line 当我尝试上传文件时,它在行中显示内存不足错误

sb.append(Base64.encode(data));

How can I solve this issue? 我该如何解决这个问题? My web service is SOAP webservice. 我的Web服务是SOAP Web服务。 Here is the complete code of the method. 这是该方法的完整代码。

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

I see two methods: 我看到两种方法:

  1. Use streamed XML writer and chunked content to avoid excessive memory consumption. 使用流XML编写器和分块内容来避免过多的内存消耗。 Not sure if it is applicable here. 不确定在这里是否适用。

  2. Use MTOM to send SOAP messages with attachments. 使用MTOM发送带有附件的SOAP消息。

This method is preferable, but you must add required functionality to your webservice. 此方法是可取的,但是您必须向Web服务中添加所需的功能。

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

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