Программисты JAVA общаются здесь
-
Anonymous
Обязательный параметр MultipartFile «файл» отсутствует в Spring MVC
Сообщение
Anonymous »
Я пытаюсь добавить функцию загрузки изображения в мое приложение Spring MVC.
часть jsp:
конфигурация:
контроллер:
Код: Выделить всё
@RequestMapping(value="/member/createCompany/uploadImage", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(
@RequestParam("file") MultipartFile file){
String name = "image_name";
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name + "-uploaded")));
stream.write(bytes);
stream.close();
return "You successfully uploaded " + name + " into " + name + "-uploaded !";
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}
После того, как я выбрал изображение, я нажимаю «Загрузить» и вижу сообщение об ошибке:
Код: Выделить всё
HTTP Status 400 - Required MultipartFile parameter 'file' is not present
Что я делаю не так?
Подробнее здесь:
https://stackoverflow.com/questions/271 ... spring-mvc
1733770416
Anonymous
Я пытаюсь добавить функцию загрузки изображения в мое приложение Spring MVC.
часть jsp:
[code]...
...
[/code]
конфигурация:
[code]...
...
[/code]
контроллер:
[code] @RequestMapping(value="/member/createCompany/uploadImage", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(
@RequestParam("file") MultipartFile file){
String name = "image_name";
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name + "-uploaded")));
stream.write(bytes);
stream.close();
return "You successfully uploaded " + name + " into " + name + "-uploaded !";
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}
[/code]
После того, как я выбрал изображение, я нажимаю «Загрузить» и вижу сообщение об ошибке:
[code]HTTP Status 400 - Required MultipartFile parameter 'file' is not present
[/code]
Что я делаю не так?
Подробнее здесь: [url]https://stackoverflow.com/questions/27101931/required-multipartfile-parameter-file-is-not-present-in-spring-mvc[/url]