Answer the question
In order to leave comments, you need to log in
How to specify a directory to upload a file?
here is a sample code:
@RequestMapping(value="/upload", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file){
if (! file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name + ".png")));
stream.write(bytes);
stream.close();
} catch (Exception e) {
..............
}
} else {
..
}
}
how do I specify the path to save the file in the project on the server?
given that the project can be deployed on different servers!)
Answer the question
In order to leave comments, you need to log in
Instead of an option to save in the same directory where it is executed?
For example:
./myFolder/myFile.png
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question