This is a sample project on how to asynchronously upload and download files using the Servlet 3.1 API and the new non-blocking I/O support.
The files can be of any size and many can be uploaded at the same time without blocking the application.
The timeout and buffer size has to be adjusted according to the application's file needs.
The application server used for running this sample has to be adjusted as well for NIO worker thread pool size and timeout, and the request post max size.
This is just a sample, some error cases have to be taken into account to be used in a production application, like correctly catching each possible exception.
This sample uses the ExtJS 4.2.1 javascript framework and the upload widget from Ivan Novakov for the async simultaneous uploads GUI:
http://www.sencha.com
https://github.com/ivan-novakov/extjs-upload-widget
For adjusting the application's file upload timeout and stream buffer size you need to modify the following files:
- line 18: set uploadTimeout in milliseconds, default is 1 hour
- line 24: set the timeout in milliseconds, default is 1 hour
- line 36: set the upload buffer in bytes, default is 1MB
- line 32: set the download buffer in bytes, default is 1MB
- You have to use the web GUI, the default URL is http://localhost:PORT/upload
- Set the server's upload path in the window toolbar's text field, i.e. C:\uploads
- Click on the browse button and select as many files as you need, you can do this many times and the files are queued in the window grid.
- When you're done, click on the upload button.
- You can also abort uploads, remove certain files from the grid by selecting them using the checkbox column or you can remove all form the list.
- http://localhost:PORT/upload/file?path=FILE_SYSTEM_PATH
- i.e. http://localhost:8080/upload/file?path=C:\uploads\some-file.txt