From 1e32024292fee39e0f9ed6898c01b7067c12b6e1 Mon Sep 17 00:00:00 2001 From: Daniel DeGroff Date: Mon, 2 Jun 2025 13:42:34 -0600 Subject: [PATCH 1/5] working --- design/file-upload.md | 64 ++++++++++++ java-http.ipr | 15 +++ .../fusionauth/http/FileUploadDisabled.java | 24 +++++ .../fusionauth/http/FileUploadException.java | 24 +++++ .../fusionauth/http/FileUploadTooLarge.java | 29 ++++++ .../http/MultipartRequestTooLarge.java | 29 ++++++ .../http/io/MultipartProcessor.java | 40 ++++++++ .../io/MultipartProcessorConfiguration.java | 97 +++++++++++++++++++ .../fusionauth/http/io/MultipartStream.java | 91 ++++++++++++++++- .../fusionauth/http/server/HTTPRequest.java | 18 +++- .../io/fusionauth/http/MultipartTest.java | 7 +- 11 files changed, 429 insertions(+), 9 deletions(-) create mode 100644 design/file-upload.md create mode 100644 src/main/java/io/fusionauth/http/FileUploadDisabled.java create mode 100644 src/main/java/io/fusionauth/http/FileUploadException.java create mode 100644 src/main/java/io/fusionauth/http/FileUploadTooLarge.java create mode 100644 src/main/java/io/fusionauth/http/MultipartRequestTooLarge.java create mode 100644 src/main/java/io/fusionauth/http/io/MultipartProcessor.java create mode 100644 src/main/java/io/fusionauth/http/io/MultipartProcessorConfiguration.java diff --git a/design/file-upload.md b/design/file-upload.md new file mode 100644 index 0000000..261197d --- /dev/null +++ b/design/file-upload.md @@ -0,0 +1,64 @@ +### File Upload + + + +### Use Cases +1. Restrict file uploads + - In a multi +2. Allow uploads all the time +3. Allow uploads, mvc Action dependant +4. Allow uploads, mvc Action dependant, delete on action completion. + - This means the action is responsible to: + - Move the file + - Tell us not to delete it + + + +### Examples + +### Spring Boot + +- https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java + +`MultipartProperties.java` +```java +/** + * Whether to enable support of multipart uploads. + */ +private boolean enabled = true; + +/** + * Intermediate location of uploaded files. + */ +private String location; + +/** + * Max file size. + */ +private DataSize maxFileSize = DataSize.ofMegabytes(1); + +/** + * Max request size. + */ +private DataSize maxRequestSize = DataSize.ofMegabytes(10); + +/** + * Threshold after which files are written to disk. + */ +private DataSize fileSizeThreshold = DataSize.ofBytes(0); + +/** + * Whether to resolve the multipart request lazily at the time of file or parameter + * access. + */ +private boolean resolveLazily = false; +``` + + +#### Summary +- Accept Multi-Part +- See ContentDisposition with a file, collect meta-data about the file, do not create a file yet. +- Uses Servlet handling and "parses" the request if not set to lazily. This functionally does what we are doing, it writes all the files to disk. + + +io.undertow.server.handlers.form.FormDataParser - has a `close()` method and deletes all files on close. diff --git a/java-http.ipr b/java-http.ipr index 8a79f77..a093491 100644 --- a/java-http.ipr +++ b/java-http.ipr @@ -346,12 +346,14 @@