How can i restrict the size of multipart-request in Jersey 2.0 RestFull api implementation? eg. I have developed one API that accepts ("multipart/mixed") request, First Bodypart is JSON data and the second Bodypart is file, I want to restrict incoming stream to 5mb only using some annotation or stream wrapper on the inbound http input stream. Or is there any way to read incomming stream in parts so that i dont have to write full stream to temp file to check its size?
Asked
Active
Viewed 826 times
1
-
Have you tried just checking the Content-Length header? Usually that should be set. – Paul Samsotha Oct 08 '15 at 13:45
-
Yes i did tried that and Content-Length was there but i dont want to do it in that way, iam looking for something like @MultipartConfig anotation in my Jersey REST implementation that restricts file size limit – Simer Oct 09 '15 at 06:07
-
I don't think there is anything like that that Jersey offers.You can implement it yourself in a filter using the Content-Length. See [Filters and Interceptors](https://jersey.java.net/documentation/latest/filters-and-interceptors.html). Aside from the filter, you can try to [set the config in the web.xml](http://stackoverflow.com/q/19145489/2587435). I don't know if it will have any affect for Jersey though. You can try it. – Paul Samsotha Oct 09 '15 at 06:15
-
I did try config settings in web.xml but it did't work with jersey,may be i have to explore it more. – Simer Oct 09 '15 at 06:46
-
Also i found some performance issue when i am calling my POST method for uploading files, In backends a method org.jvnet.MimeMessage.getAttachments() is taking around 1.7 seconds to execute which is a major performance issue,i guess jersey is internally using this method.I got this from the performance team using Dyntrace Monitoring tool. – Simer Oct 09 '15 at 06:50
-
Have you found the solution to this ? – Adrian Bob Jun 05 '18 at 22:29