Giter VIP home page Giter VIP logo

servlet-fileupload-examples's Introduction

servlet-fileupload-examples

Example projects showing the way of uploading files by using Commons FileUpload, servlet and Spring Boot.

Projects

Simple servlet web application using Commons FileUpload and servlet standard file upload components. One of its endpoints utilizes Commons FileUpload Streaming API.

This project uses jakarta EE 8.

Spring Boot application using Commons FileUpload. This application also utilizes Streaming API.

This project uses Spring Boot version 2(Spring framework version 5).

Spring Boot application using servlet standard file upload components.

This project uses Spring Boot version 2(Spring framework version 5).

Spring Boot application using Commons FileUpload with Spring Security.

In this application, we send a multipart HTTP request including a CSRF token. The CSRF token is included in URL. We have to prevent the Spring's multipart resolver from parsing the HTTP request body so that we have to make it possible for Commons FileUpload Streaming API to parse it.

Spring Boot application using Commons FileUpload Streaming API. This project uses Spring Boot version 3 (which depends on Spring framework version 6). From version 6, Spring requires jakarta EE 9+. This means that it requires jakarta.* namespace.

Even the latest version of Commons FileUpload isn't integrated with jakarta.* namespace. It still depends on old javax.* namespace.

So Spring no longer supports the components for Commons FileUpload(e.g. CommonsMultipartResolver. Related issue: Drop outdated Servlet-based integrations: Commons FileUpload, FreeMarker JSP support, Tiles).

This project can become a rescue for someone who wants to keep using Commons FileUpload with Spring framework.

In this project, we use Eclipse Transformer project in order to convert from javax.* namespace to jakarta.* namespace in Commons FileUpload jar and we directly call Commons FileUpload API(Streaming API) in the controller's methods in the Spring Boot application.

MISC

Logging

The applications in this project output logs about changes on the temporary directory(javax.servlet.context.tempdir) by utilizing WatchService API.

If we don't use Commons FileUpload Stream API, uploaded files are written to the directory if the files are considered 'large' files. By default, files larger than 1KB are considered 'Large' files in this project.

reference:

Create large files for testing

dd if=/dev/zero of=1g.img bs=1 count=0 seek=1G

reference:

Output GC logs for Spring Boot applications

./mvnw clean package
java -Xlog:gc:${HOME}/work/gc.log -jar target/${APPLICATION_JAR_NAME}.jar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.