Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Document how MultiPartFile.transferTo works with Servlet 3 [SPR-12650] #17251
When a multipart file upload is attempted using Spring MVC, MultiPartFile object is received.
The documentation (http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/MultipartFile.html#transferTo-java.io.File-) then says that the transferTo(File destination) method will move the uploaded file to the provided location.
Well on Jetty 9 it won't..
The reason for this is hidden in org.eclipse.jetty.util.MultiPartInputStreamParser.MultiPart#write(java.lang.String) which tries to do the following (the second codepath does that in the same way):
The filename argument bubbles there from:
The destination itself is correct, but the File(parent, path) constructor will always convert it to relative path and prefix it with the _tmpDir. That will convert path like /home/myuser/destination.txt to /tmp/home/myuser/destination.txt on my system.
Now this might be Jetty's fault, but it essentially means that the transferTo method is useless for Jetty backed application, because there is no way to give it an absolute path.
Rossen Stoyanchev commented
The Javadoc for Part.write says "The file is created relative to the location as specified in the MultipartConfig". I think you need to configure that. This can be confirmed in Jetty's MultiPartInputStreamParser which initializes the _tmp variable from _config.getLocation() or otherwise falls back on "java.io.tmpdir".