java - Filter for limiting the file size on upload in Jersey - Stack Overflow
This is because the browser doesn't look for a server response until AFTER it has sent the complete request.
Here are two ways to stop large file uploads before they arrive at your server:
1) Client-side scripting. An applet (Java file upload) or browser plug-in (Flash file upload, ActiveX, or whatever) can check the size of the file and compare it to what you declare to be the limit (you can use the OPTIONS request for this or just include the maximum size allowed in your form as either a hidden input or non-standard attribute on the file input element).
2) Use a 3rd party data service such as Amazon S3 that allows uploads directly from the browser. Set up the form on the page so that it uploads to the data service, and on success invoke some javascript function you write that notifies your server about an available file upload (with the instance details). Your server then sends a request to the data service to find out the size of the file... if it's small enough you retrieve it from the server side. If it's too large you just send a delete request to the data service and then send your response to the browser (your javascript function) that the file was too large and they need to do it again. Your javascript function then affects the display to notify the user.
Read full article from java - Filter for limiting the file size on upload in Jersey - Stack Overflow
No comments:
Post a Comment