11

File Upload Download with Jersey Demo App

 3 years ago
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.
neoserver,ios ssh client

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:

  1. Single File Upload using FormDataBodyPart
  2. Single File Upload using InputStream
  3. Multiple File Upload
  4. File Upload Integration with the Blueimp jQuery File Upload Plugin
  5. File Download of multiple file types
  6. 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.

fupload0410a.png

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.

fupload0410b.png

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.

fupload0410c.png

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.

fupload0410d.png

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.

fupload0410e.png

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.

fupload0410f.png

When the user logs in they are directed back to the File Downloads menu with an Alert displaying their file access.

fupload0410g.png

Handling Unauthorized File Access

When a user without admin file access tries to download an admin file they are redirected to the Unauthorized page.

fupload0410h.png

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.

CategoriesJavaTagsBootique, Java, Javascript, Jersey, Shiro


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK