Zhaops %!s(int64=6) %!d(string=hai) anos
pai
achega
8e4e21cd95

+ 16 - 3
icssman-service/src/main/java/com/diagbot/web/UploadController.java

@@ -1,9 +1,12 @@
 package com.diagbot.web;
 
+import com.diagbot.dto.FileDTO;
 import com.diagbot.facade.UploadFacade;
 import com.diagbot.util.FastJsonUtils;
+import com.diagbot.util.StringUtil;
 import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,6 +15,9 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 @RestController
 @Api(value = "文件上传API", tags = { "文件上传API" })
 @RequestMapping(value = "/file")
@@ -21,9 +27,16 @@ public class UploadController {
     private UploadFacade uploadFacade;
 
     @CrossOrigin(allowCredentials = "true", allowedHeaders = "*", methods = { RequestMethod.POST }, origins = "*")
-    @PostMapping(value = "/uploadImage", produces = "application/json;charset=UTF-8")
-    public String singleFileUpload(@RequestParam("upfile") MultipartFile file) {
-        String data = FastJsonUtils.getBeanToJson(uploadFacade.singleFileUpload(file));
+    @PostMapping(value = "/uploadImage", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+    public String singleFileUpload(@RequestParam("upfile") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
+        FileDTO fileDTO = uploadFacade.singleFileUpload(file);
+        String data = FastJsonUtils.getBeanToJson(fileDTO);
+        response.setContentType("text/plain;charset=UTF-8");
+
+        String callback = request.getParameter("callback");//客户端请求参数
+        if (callback != null && StringUtil.isNotBlank(callback)) {
+            data = callback + "(" + data + ")";
+        }
         return data;
     }