文件上传下载的开发文档参考:
* https://docs.servicecomb.io/java-chassis/zh_CN/general-development/file-upload.html
* https://docs.servicecomb.io/java-chassis/zh_CN/general-development/file-download.html
代码示例可以参考ServiceComb提供的DEMO:https://github.com/apache/servicecomb-java-chassis
里面有大量的开发示例,下载的示例在DownloadSchema.java, 上传的在CodeFirstSpringmvc.java
快速参考:
上传
| 1 2 3 4 5 6 | @RequestMapping(path = "/upload", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @Override public String fileUpload(@RequestPart(name = "file1") MultipartFile file1, @RequestPart(name = "someFile") MultipartFile file2, @RequestAttribute("name") String name) { return super.fileUpload(file1, file2, name); } |
下载
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // generate HttpHeaders.CONTENT_DISPOSITION to be "attachment;filename=tempFilePart.txt" automatically @GetMapping(path = "/tempFilePart") public Part tempFilePart(String content) throws IOException { File file = createTempFile(content); return new FilePart(null, file) .setDeleteAfterFinished(true) .setSubmittedFileName("tempFilePart.txt"); } @GetMapping(path = "/file") public File file(String content) throws IOException { return createTempFile("file.txt", content); } |