V
V
Valera Programmer2015-01-16 12:03:36
Java
Valera Programmer, 2015-01-16 12:03:36

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

2 answer(s)
B
Billy Milligan, 2015-01-16
@noddux

Instead of an option to save in the same directory where it is executed?
For example:
./myFolder/myFile.png

W
wscms, 2017-07-10
@lemonlimelike

Quotes?
$_GET['id']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question