0

Is there a limit for the file size when sending MultiPart Rest call with Java (not with Spring)?

We have a code, similar to this one: (same implementation, using 'HttpURLConnection' and 'OutputStream') https://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically

Maybe the limitation is the 'OutputStream' size limit?

would appreciate your help, thanks!

I've tried to upload big files, but I couldn't find a server that will get more than 10MB. Also tried to understand which Java Object is my bottleneck and got confused . . .

Gonzo
  • 13
  • 4

1 Answers1

0

In general the max size of a request (e.g. POST) can either be controlled by the container/server (e.g. Tomcat) or the application. The default behavior for containers vary, refer default for Tomcat. In addition, applications may also impose a size limit. Limiting size for uploads is in general a common feature to limit security related incidents.

If you have access to the servers and the applications you could check their configurations.

Ironluca
  • 3,402
  • 4
  • 25
  • 32
  • Hi Ironluca, Thanks for your answer. In my case I control only the client side. So my question is if there is a limit, if my implementation is with Java using the 'OutputStream' Object when uploading big files (>250MB~). – Gonzo Jul 12 '23 at 08:57
  • The limiting is happening on server side not in OutputStream – Ironluca Jul 12 '23 at 11:25
  • OK, thanks! (I guess it also depends on the OS it runs on, I got the 'java.lang.OutOfMemoryError: Java heap space' Exception on a VM with poor resources_ – Gonzo Jul 13 '23 at 07:39
  • Hey, One more thing, If I want the body data to be uploaded to the server in chunks. I can add data to the OutputStream, flush and then add more data and flush, right? I can do it several times and the server will get it as a whole? but in chunks? I want to reduce the memory use in the client side. Thanks! – Gonzo Jul 18 '23 at 05:36
  • You can flush intermittently and the server will get it all right, it is however not chunking, for chunking transfer encoding needs to be done, it is mostly done by servers. In your case, you don't need to use that. Refer: https://www.oracle.com/technical-resources/articles/javame/chunking.html – Ironluca Jul 18 '23 at 08:08
  • BTW, I ended up using apache httpclient instead of the old 'HTTPURLConnection'. The 'MultipartEntityBuilder' does everything for me. Thanks! – Gonzo Aug 13 '23 at 17:35
  • Yes, Apache HTTP Component client is a good library – Ironluca Aug 14 '23 at 08:37