|
@@ -1,8 +1,9 @@
|
|
|
package com.yaoxiang.diagnosis.controller;
|
|
|
|
|
|
import com.yaoxiang.diagnosis.file.FileService;
|
|
|
+import com.yaoxiang.diagnosis.util.CommonUtil;
|
|
|
import com.yaoxiang.diagnosis.util.OSSUtil;
|
|
|
-import com.yaoxiang.diagnosis.model.ResponseMessage;
|
|
|
+import com.yaoxiang.diagnosis.model.Reply;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
@@ -12,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
|
|
|
* @AUTHOR: DaiFengWen
|
|
@@ -28,36 +30,50 @@ public class FileController {
|
|
|
private FileService fileService;
|
|
|
|
|
|
@RequestMapping(value = "/img", method = RequestMethod.PUT)
|
|
|
- public ResponseMessage uploadImg(@RequestParam MultipartFile file) {
|
|
|
+ public Reply uploadImg(@RequestParam MultipartFile file) {
|
|
|
String file_name = null;
|
|
|
try {
|
|
|
int suffixIndex = file.getOriginalFilename().lastIndexOf(".");
|
|
|
String suffix = file.getOriginalFilename().substring(suffixIndex);
|
|
|
file_name = OSSUtil.INSTANCE.putFile(file.getInputStream(), suffix);
|
|
|
- return ResponseMessage.getInstance(200, file_name);
|
|
|
+ return Reply.getInstance(200, file_name);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return ResponseMessage.getInstance(500, "error");
|
|
|
+ return Reply.getInstance(500, "error");
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "上传文件")
|
|
|
@PostMapping(value = "/upload", consumes = "multipart/*", headers = "content-type=multipart/form-data")
|
|
|
- public ResponseMessage uploadFile(@ApiParam(value = "文件") @RequestParam MultipartFile file) {
|
|
|
+ public Reply uploadFile(@RequestBody MultipartFile file) {
|
|
|
try {
|
|
|
int suffixIndex = file.getOriginalFilename().lastIndexOf(".");
|
|
|
String suffix = file.getOriginalFilename().substring(suffixIndex);
|
|
|
- return ResponseMessage.getInstance(200, OSSUtil.INSTANCE.putFile(file.getInputStream(), suffix));
|
|
|
+ String url = fileService.upload(file.getBytes(), CommonUtil.randomUUID() + suffix);
|
|
|
+ return Reply.ok(url);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return ResponseMessage.getInstance(500, "error");
|
|
|
+ return Reply.fail("error");
|
|
|
}
|
|
|
|
|
|
- @GetMapping("download/{path}/{filename}")
|
|
|
- @ApiOperation("使用方式 curl localhost:8085/file/download/doc/xx.docx")
|
|
|
- public ResponseEntity<byte[]> download(@PathVariable String path, @PathVariable String filename) throws Exception {
|
|
|
- return fileService.download(path + "/" + filename);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/download/{bucketName}/{filename}")
|
|
|
+ @ApiOperation("使用方式 curl localhost:8085/file/download/prod/xx.docx")
|
|
|
+ public ResponseEntity<byte[]> download(@PathVariable String bucketName, @PathVariable String filename) throws IOException {
|
|
|
+ return fileService.download("/" + bucketName + "/" + filename);
|
|
|
}
|
|
|
|
|
|
}
|