-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Martin Sivák opened SPR-12650 and commented
When a multipart file upload is attempted using Spring MVC, MultiPartFile object is received.
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public EmberModel upload(@RequestParam("files[]") MultipartFile[] files) {
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):
File f = new File(_tmpDir, fileName);
if (_file.renameTo(f))
_file = f;
The filename argument bubbles there from:
// org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
this.part.write(dest.getPath());
}
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.
Affects: 4.1.4
Issue Links:
- StandardMultipartFile.transferTo should fall back to manual copy if Part.write doesn't support absolute locations (e.g. on Jetty) [SPR-15257] #19822 StandardMultipartFile.transferTo should fall back to manual copy if Part.write doesn't support absolute locations (e.g. on Jetty)