@PostMapping("/upload")
public String upload(@RequestParam("abc") MultipartFile file, HttpServletRequest request) {
System.out.println("==============" + request.getContentType());
String uploadPath = "/Users/test";
String originalFileName = file.getOriginalFilename();
File local = new File(uploadPath + "/" + originalFileName);
try {
file.transferTo(local);
} catch (IllegalStateException e) {
} catch (IOException e) {
}return originalFileName;
}
使用curl上传:
curl -i-F "abc=@TLS.md" -X POSThttp://127.0.0.1:8080/upload
非form形式:
@PostMapping("/binary")
public void binary(HttpServletRequest request) throws IOException {
File destination = new File("/Users/test/abc");
ServletInputStream inputStream = request.getInputStream();
Enumeration ens = request.getHeaderNames();
ens.asIterator().forEachRemaining(t -> System.out.println(t + ":" + request.getHeader(t)));
FileUtils.copyInputStreamToFile(inputStream, destination);
}
【文件上传】使用curl上传
curl --data-binary@TLS.mdhttp://127.0.0.1:8080/binary
推荐阅读
- java|阿里巴巴开源的 Blink 实时计算框架真香
- 大数据|常见大数据面试话术(建议收藏)
- flink|【大数据面经系列】大数据开发(实时计算方向)面试题(一)
- Java|2021-07/08收集字节跳动---Java提前批面试题
- HashMap你真的了解吗?
- java|35个小妙招优化Java性能——精简篇
- html|手把手教你用vuepress搭建自己的网站(2)
- Java基础|Java中的字节流和字符流如何理解——精简
- Java基础|Java中Map集合如何理解(四)——精简