|
|
@@ -2,12 +2,17 @@ package com.sckw.example.controller;
|
|
|
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.example.service.FileService;
|
|
|
+import com.sckw.file.api.dubbo.FileApiDubboService;
|
|
|
+import com.sckw.file.api.feign.FileApiFeignService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
/**
|
|
|
* @author lfdc
|
|
|
* @version 1.0
|
|
|
@@ -21,19 +26,25 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
@RestController
|
|
|
@RequestMapping("/file")
|
|
|
@AllArgsConstructor
|
|
|
-//@RequestMapping("/export")
|
|
|
public class FileApiController {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FileApiFeignService fileApiFeignService;
|
|
|
+
|
|
|
+ @DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
+ private FileApiDubboService fileApiDubboService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FileService fileService;
|
|
|
|
|
|
/**
|
|
|
* 上传文件至OSS
|
|
|
+ *
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- @RequestMapping(value = "/fileUpload",method = RequestMethod.POST)
|
|
|
- public HttpResult fileUpload(@RequestParam("file")MultipartFile file) {
|
|
|
+ @RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
|
|
|
+ public HttpResult fileUpload(@RequestParam("file") MultipartFile file) {
|
|
|
//获取上传文件
|
|
|
String url = fileService.uploadFile(file);
|
|
|
return HttpResult.ok(url);
|
|
|
@@ -42,9 +53,10 @@ public class FileApiController {
|
|
|
|
|
|
/**
|
|
|
* OSS下载文件/获取文件地址
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping("/fileDownload")
|
|
|
+ @GetMapping("/fileDownload")
|
|
|
public HttpResult fileDownload() {
|
|
|
String fileName = "测试=JPEG.webp";
|
|
|
//获取上传文件
|
|
|
@@ -52,4 +64,40 @@ public class FileApiController {
|
|
|
return HttpResult.ok(url);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 基于feign调用
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping (value = "/fileFeignUpload",method = RequestMethod.POST)
|
|
|
+ public HttpResult fileFeignUpload(@RequestParam("file") MultipartFile file) {
|
|
|
+ //auth 服务 调用 file服务提供的feign接口
|
|
|
+ HttpResult result = fileApiFeignService.fileFeignUpload(file);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 基于dubbo调用
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("fileDubboUpload")
|
|
|
+ public HttpResult fileDubboUpload(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ // 调用 file服务提供的dubbo接口
|
|
|
+ //需要将文件转换成byte否则为空
|
|
|
+ //获取文件类型
|
|
|
+ String contentType = file.getContentType();
|
|
|
+ //获取上传文件的原始文件名
|
|
|
+ String oFileName = file.getOriginalFilename();
|
|
|
+ //把文件转化成byte[]
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+
|
|
|
+ HttpResult result = fileApiDubboService.fileUpload(contentType,oFileName,bytes);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|