I am trying to upload a file using spring . Below is my code, how I work on it, but if I try to use it, I get this response :
HTTP Status 400 - Required MultipartFile File parameter
I do not understand what a mistake is.
I use the pre-client for testing, and I upload the file as an attachment.
My javacode:
@RequestMapping(value = "/upload",headers = "Content-Type=multipart/form-data", method = RequestMethod.POST) @ResponseBody public String upload(@RequestParam("file") MultipartFile file) { String name= "test.xlsx"; if (!file.isEmpty()) { try { byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(name))); stream.write(bytes); stream.close(); return "You successfully uploaded " + name + "!"; } catch (Exception e) { return "You failed to upload " + name + " => " + e.getMessage(); } } else { return "You failed to upload " + name + " because the file was empty."; } }
source share