Java tomcat embedded with Jersey File Upload
I'm building a java application with tomcat embedded and jersey REST.
What i need to do is to implement a VERY simple (and single) file upload inside this application but i can't find anywhere a guide for my context...i just found a file upload solution but NOT with embedded tomcat.
Any suggestions?
Thanks everyone in advice and sorry for my English
If you are using Spring Boot for Tomcat embedded, then below code example will help you..
@Controller
public class FileUploadController {
@RequestMapping(value="/upload", method=RequestMethod.GET)
public @ResponseBody String provideUploadInfo() {
return "You can upload a file by posting to this same URL.";
}
@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)));
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.";
}
}
}
With ref. of https://spring.io/guides/gs/uploading-files/
链接地址: http://www.djcxy.com/p/91558.html上一篇: 正确的方式传递参数在R DBI中查询
下一篇: 嵌入泽西文件上传的Java tomcat