Я хочу сохранить загруженные изображения в определенную папку в приложении Spring 3 MVC, развернутом на Tomcat
Моя проблема заключается в том, что я не могу сохранить загруженные файлы изображений на хост, на котором выполняется приложение.
Вот что я пробовал:
private void saveFile(MultipartFile multipartFile, int id) throws Exception {
String destination = "/images/" + id + "/" + multipartFile.getOriginalFilename();
File file = new File(destination);
multipartFile.transferTo(file);
}
Результат: FileNotFoundException - Да, конечно, я хочу создать этот файл!?!
Я попробовал его с помощью context.getRealPath
или getResources("destination")
, но без каких-либо успехов.
Как создать новый файл в определенной папке моего приложения с содержимым моего многостраничного файла?