0

This is my current request scoped bean:

@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public CustomMultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setMaxUploadSize(10485760); // 10 MB
    resolver.setMaxInMemorySize(1048576); // 1 MB
    return resolver;
}

How could I get request information each time my bean is created?

Jordi
  • 20,868
  • 39
  • 149
  • 333
  • Making the multipartresolver request scoped is pretty useless. – M. Deinum Apr 13 '23 at 07:56
  • I'm aware of it. I'm trying to design a way to receive multipart files and put them directly to a "persistent" directory "/data/{day}/{month}/{year}/{requestId}". I was trying to initialize my `MultiPartResolver` per request and trying to populate request information in order to save received file to above directory structure. Is there a way to get it using `CommonsMultipartResolver`? – Jordi Apr 13 '23 at 08:14
  • Storing should be done in your controller, and thus scoping the multipart resolver to the request is pretty much useless. – M. Deinum Apr 13 '23 at 08:15
  • Here there are two phases: `receiving`, `storing`. I'd like to get both into only one step. I need to get a high performance and I don't want to store (copy) again received file into an another place. We could receive high volume files, and that implies to move and remove high volume files. – Jordi Apr 13 '23 at 08:18
  • Why would you need to copy it again, that is were yuo are wrong. Receive the file streamin in your controller and write, no need to store it somewhere else first. – M. Deinum Apr 13 '23 at 08:34
  • Received files are first stored into a `temp` directory and passed as a `MultipartFile` parameter to the controller. Once inside controller, tipically is moved as InputStream to a file into a second directory. – Jordi Apr 13 '23 at 08:37
  • That depends on how you receive it. You can receive it streaming without storing it (as stated that is were you are wrong). The gist of it all is in [this answer](https://stackoverflow.com/questions/15432024/how-to-upload-a-file-using-commons-file-upload-streaming-api) including the upload controller to use. This doesnt store it in a tempfile, nor in-memory but will receive it streaming. You will actually have to disable the file upload in your spring boot application so it doesn't use a multipartresolver. – M. Deinum Apr 13 '23 at 08:43

0 Answers0