OutputStream OutOfMemoryError when sending HTTP

前端 未结 6 1756
深忆病人
深忆病人 2020-12-01 16:53

I am trying to publish a large video/image file from the local file system to an http path, but I run into an out of memory error after some time...

here is the code

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 17:21

    The problem is that the HttpURLConnection class is using a byte array to store your data. Presumably this video you are pushing is taking more memory than available. You have a few options here:

    1. Increase the memory to your application. You can use the -Xmx1024m option to give 1GB of memory to your application. This will increase the amount of data you can store in memory.

    2. If you still run out of memory, you might want to consider trying another library to push the video up that does not store the data all in memory at once. The Apache Commons HttpClient has such a feature. See this site for more information: http://hc.apache.org/httpclient-3.x/features.html. See this section for multi-part form upload of large files: http://hc.apache.org/httpclient-3.x/methods/multipartpost.html

提交回复
热议问题