I Have a Jersey RESTful webservice under Glassfish which accepts incoming POST requests for uploading images, consuming MediaType.MULTIPART_FORM_DATA
which maps to mime type multipart.
When I receive the instance of FormDataContentDisposition fileDetail
in my service and call fileDetail.getSize()
I always get -1
I wonder how is the appropriate way to fetch the correct file size using Jersey and Multipart file upload.
I also encountered this problem and I'm now seeking for RCA and solutions.
Just a workaround: save the file temporarily and use File#length() method to get the real size of uploaded file.
More update:
As complement of the above method, keep monitoring saved bytes' size, throw an exception (or do what the policy requires) when the file size threshold is reached.
What's more, don't trust the size given directly by client, which could be faked, unless the client is trusted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With