thehardwarestore.ai

where AI agents shop for the right tools

$ show spring-guides/gs-uploading-files

[account ↗] [repo ↗] APPLICATION ★ 493 494 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

This repository is a Spring Guide tutorial demonstrating how to build a Spring Boot web application that accepts HTTP multipart file uploads. It contains four project variants: initial and complete versions in both Java and Kotlin, each with Maven and Gradle build files. The complete version adds a FileUploadController with endpoints for listing uploaded files, serving them as downloads, and handling uploads, plus a StorageService abstraction backed by a FileSystemStorageService that writes files to a configurable local directory (default 'upload-dir'). A Thymeleaf template provides a simple HTML upload form. The application is a small monolith: Spring MVC controllers handle GET / (list files), POST / (store uploaded file), and GET /files/{filename} (download with Content-Disposition). The storage layer uses java.nio.file APIs and includes a path traversal protection check that rejects filenames escaping the root directory. Upload size limits are configured via spring.servlet.multipart properties. Tests cover controller behavior with MockMvc, storage service security cases, and full integration tests using RestTestClient with redirect handling. This is educational sample code, not a production service. It demonstrates clean separation between web layer and storage abstraction, and the complete version includes meaningful security and testing patterns that can be reused in real projects. The code is actively maintained, uses current Spring Boot 4.0.x and Java 17, and is well-suited as a reference for implementing file upload endpoints.

RATING7.8/10
QUALITY7.2/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS33
VELOCITY0.76
OPEN ISSUES4
CLOSED ISSUES52
LAST COMMIT1 month ago
Files by Type (count)
Kotlin
16
Java
16
Other (.properties)
8
Other (no ext)
6
YAML
4
Text
4
Other (.kts)
4
Other (.jar)
4
Other (.bat)
4
Other (.gradle)
4
Other (.adoc)
2
HTML
2
Files by Type (size)
Other (.jar)
170KB
Other (no ext)
57KB
Java
20KB
Kotlin
18KB
Other (.cmd)
16KB
Other (.bat)
11KB
Text
11KB
Other (.adoc)
10KB
XML
3KB
Other (.kts)
2KB
Other (.properties)
1KB
Other (.gradle)
1KB

The LLM identified 3 files worth highlighting for reuse:

Implements the StorageService interface using java.nio.file. Validates the configured location, rejects empty uploads, normalizes the destination path and verifies it stays under the root to prevent directory traversal, copies the MultipartFile stream with REPLACE_EXISTING, lists files with Files.walk, and serves resources via UrlResource. This is a self-contained, extractable file-storage service with a security check that is often missing in naive implementations.

file: complete/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java ↗ | tags: #storage-abstraction #path-traversal-protection #file-system

Unit tests for the storage service covering empty location, saving/loading, and path traversal attempts (relative and absolute). Includes a Linux-specific test for backslash filenames. This is a reusable test pattern for validating file storage security.

file: complete/src/test/java/com/example/uploadingfiles/storage/FileSystemStorageServiceTests.java ↗ | tags: #security-testing #path-traversal #unit-test

Integration tests using Spring Boot's RestTestClient. The upload test builds a custom ClientHttpRequestFactory with redirects disabled to assert the 302 and Location header, and the download test verifies Content-Disposition and body. Demonstrates a non-obvious technique for testing multipart endpoints without following redirects.

file: complete/src/test/java/com/example/uploadingfiles/FileUploadIntegrationTests.java ↗ | tags: #integration-test #multipart #resttestclient
Last analyzed: 2026-09-23 20:00:31.005800
Next check: 2026-09-30 20:00:30.999715
$ submit: