I use Servlet 3 @MultiPartConfig
annotation to implement file upload in my application. I need set multipart-config location parameter at the runtime (not hardcode in annotaion parameter). Is there any API for programmatic access to multipart-config of servlet?
Thanks
I had your same problem too and the solution is simple: standard Servlet 3.0 file upload is not enough: just grab the jars from Apache FileUpload Commons and you're done
Just look at this crystal clear example with Streaming API
The @MultiPartConfig is really just a marker interface for the container. When the servlet is initialized the annotation values provided are mapped to it with a proxy object. When the incoming request is a multipart/form-data the parts of the upload are mapped to the request, and the container performs the necessary work based upon the values from the annotation and the parts on the request. There is no way for you to intercept this process since it all happens within the guts of the container. However, there is one alternative. It requires performing a file system operation a second time. Since you have all the parts you can reconstruct the file and "re-upload" it to the location of your choice. It might look something like the method below. Keep in mind although I tested this quickly in a servlet of my own to demonstrate the concept it is obviously not finished code: