OiO.lk Blog java Java HttpsUrlConnection’s setFixedLengthStreamingMode doesn’t resume file upload
java

Java HttpsUrlConnection’s setFixedLengthStreamingMode doesn’t resume file upload


I am trying to upload a large file (say 100 MB) to aws s3 using HttpsUrlConnection. My application runs in unpredictable and unstable network, hence I expect connectivity drops during the upload.

Whenever the connectivity drops and comes back, I want to resume the upload. This works perfectly for smaller files, but then when I use larger files I get OutOfMemoryException (as the data is buffered in memory).

So I tried using setFixedLengthStreamingMode() method and this doesn’t buffer the whole data in memory and flushes the data to Output stream in small chunks which resolved the OOM issue. However the upload doesn’t resume when the connectivity drops and comes back in this case. I get a “broken pipe” issue.

So basically I need a solution where I can resume the upload as well as upload in chunks.

I’ve been breaking my head on this for so many days, any idea or suggestion would be of great help. Thanks in advance!!

Note: My app can’t use any SDKs or 3rd party libraries. I have to achieve this using native Java only.



You need to sign in to view this answers

Exit mobile version