Automatically remove multipart temporary files
When files are uploaded to an Armeria server with multipart/form, it is stored to multipartUploadsLocation() when @Param of annotated services or GraphQL multipart request is used.
https://armeria.dev/docs/server-multipart#using-typeparam-annotation
https://github.com/line/armeria/blob/0a5a3d7a2f74f51a4893270a6f4aeac5f7e3c575/graphql-protocol/src/main/java/com/linecorp/armeria/server/graphql/protocol/AbstractGraphqlService.java#L101-L103
As Armeria does not automatically delete the uploaded files, users should manually remove the temporary files themselves. https://github.com/line/armeria/blob/0a5a3d7a2f74f51a4893270a6f4aeac5f7e3c575/graphql-protocol/src/main/java/com/linecorp/armeria/server/graphql/protocol/AbstractGraphqlService.java#L101-L103
It would be useful if we provided some options for how to handle multipart files.
enum MultipartRemovalStrategy {
/**
* This option would be preferred if a file is transferred using an asynchronous job.
* Users may want to delete the file when the job is done.
*/
NEVER,
/**
* Remove after a response for the multipart request is fully sent.
*/
ON_RESPONSE_COMPLETE,
/**
* Clean up all temporary files when JVM shuts down.
* File.deleteOnExit() could be used for this option
*/
ON_JVM_SHUTDOWN
}
The option can be set via ServerBuilder, VirtualHostBuilder, or ServiceBindingBuilder.
Server
.builder()
.multipartRemovalStrategy(MultipartRemovalStrategy.ON_RESPONSE_COMPLETE)
...