Skip to content

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented Sep 21, 2025

  • Adds new methods to Context to set/retrieve objects in the attributes by their class
  • new module for file uploads
  • file upload plugin adds a filter that sets a file upload service into the request attributes

(not sure about the class/method names)

// Example: Registering the plugin with a custom configuration
var jex = Jex.create();
var uploadPlugin = FileUploadPlugin.create(config -> {
    // Set the maximum file size for a single upload to 50 MB
    config.maxFileSize(50, SizeUnit.MB);
    // Set the cache directory for large files
    config.cacheDirectory("/var/tmp/jex-uploads");
});
jex.register(uploadPlugin);

Within the route handlers, you can then retrieve the io.avaje.jex.file.upload.FileUploadService from the context attributes and use it to access the uploaded files.

// Example: Handling a file upload in a POST route
jex.post("/upload", ctx -> {
    // Get the FileUploadService from the request context
    FileUploadService service = ctx.attribute(FileUploadService.class);
    // Retrieve the uploaded file using its form field name
    MultiPart uploadedFile = service.uploadedFile("image-file");

    if (uploadedFile != null) {
        System.out.println("File name: " + uploadedFile.filename());

    }
    ctx.status(200).result("File upload successful!");
});

resolves #302

@SentryMan SentryMan added this to the 3.3 milestone Sep 21, 2025
@SentryMan SentryMan requested a review from rbygrave September 21, 2025 23:49
@SentryMan SentryMan self-assigned this Sep 21, 2025
@SentryMan SentryMan added the enhancement New feature or request label Sep 21, 2025
rbygrave
rbygrave previously approved these changes Oct 6, 2025
@SentryMan SentryMan enabled auto-merge (squash) October 6, 2025 03:59
@SentryMan SentryMan disabled auto-merge October 6, 2025 04:30
@SentryMan SentryMan merged commit a6a74c3 into master Oct 6, 2025
11 checks passed
@SentryMan SentryMan deleted the multipart branch October 6, 2025 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multipart File Support
2 participants