File Upload Download with Jersey Demo App
source link: https://nixmash.com/java/file-upload-download-with-jersey-demo-app/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
File Upload Download with Jersey Demo App
You'll find a new NixMash demo app on GitHub: NixMash Upload Download with Bootique Jersey. It demos the following functions:
- Single File Upload using FormDataBodyPart
- Single File Upload using InputStream
- Multiple File Upload
- File Upload Integration with the Blueimp jQuery File Upload Plugin
- File Download of multiple file types
- Secure File Download by User Role
We'll dig into the various functions in separate blog posts. Today we'll walk through the screenshots so you'll know what is available.
Home Page
The Home Page lists the functions to date, those listed in the above list.
Single File Uploads
Here we're uploading a single file, with the option of using a @FormDataParam InputStream or a FormDataBodyPart approach. We're using the Bootstrap FileStyle enhancement to get the good looking Input controls.
MultiFile Uploads
Here we're extending the Single File Uploads with the ability to uploadĀ multiple files using List<FormDataBodyPart> on the server and some good old fashioned Javascript on the client.
Jersey Integration with Blueimp
This is probably the biggest draw of the demo app, using the Blueimp jQuery File Upload Plugin with Jersey on the backside. I integrated Blueimp with Spring Boot which I wrote about here, and wanted to do the same in the cleaner environment of Bootique Jersey.
File Downloads
Here are theĀ File Downloads options. We're demonstrating public downloads as well as two different security levels of file access based on User Role: user and admin.
User Authentication
To secure files we need user authentication so there is Apache Shiro to handle that for us, with the two supported demo accounts.
When the user logs in they are directed back to the File Downloads menu with an Alert displaying their file access.
Handling Unauthorized File Access
When a user without admin file access tries to download an admin file they are redirected to the Unauthorized page.
As I said, we'll get into the particulars in future posts. In those posts you'll see links back to this post for reference.
Source Code Notes for this Post
Source code discussed in this post is found in my File Upload and Download in Bootique Jersey app on GitHub.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK