This is an example project for a file upload in Spring Boot 3.5.7. Uploads can be part of any form using DTOs. In this example you can manage profiles with a resume in PDF or DOC format in a Thymeleaf frontend. Implementation details:
- Separate table
FileContentfor storing file content - The entity
Profilecontains a JSON objectFileDatawith the name and UID of the file - The
FileDataServiceprovides utility functions for uploads and downloads - The
ConverterConfigregisters a converter for transforming uploads fromMultipartFileto aFileDataobject transparently - The annotation
ValidFileTypeensures the correct file type
This project was created using Bootify.io. Choose your preferred frontend and preferences, create your own database schema including file fields, and get a working Spring Boot application directly in your browser.
Update your local database connection in application.yml or create your own application-local.yml file to override settings for development.
During development it is recommended to use the profile local. In IntelliJ -Dspring.profiles.active=local can be added in the VM options of the Run Configuration after enabling this property in "Modify options".
After starting the application it is accessible under localhost:8080.
The application can be built using the following command:
mvnw clean package
Start your application with the following command - here with the profile production:
java -Dspring.profiles.active=production -jar ./target/file-upload-0.0.1-SNAPSHOT.jar
If required, a Docker image can be created with the Spring Boot plugin. Add SPRING_PROFILES_ACTIVE=production as environment variable when running the container.
mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=io.bootify/file-upload
