Browse Source

uploadBallScreenVideo

lyhzzz 3 năm trước cách đây
mục cha
commit
b1f579405f

+ 3 - 5
src/main/java/com/cdf/httpClient/client/FdkkClient.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.cdf.httpClient.request.*;
 import com.cdf.httpClient.response.FdkkResponse;
 import com.dtflys.forest.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.HashMap;
 import java.util.List;
@@ -111,10 +112,6 @@ public interface FdkkClient {
     @Address(source = FdkkSceneAddressSource.class)
     FdkkResponse uploadFiles(@Query FdkkUploadRequest fdkkUploadRequest, @DataFile("files") List<String> files, @Header("token")String token);
 
-    @Post("/service/scene/edit/upload/files")
-    @Address(source = FdkkSceneAddressSource.class)
-    FdkkResponse uploadFiles(@Body FdkkUploadRequest fdkkUploadRequest, @Header("token")String token);
-
     /**
      * 获取场景详情-查看页面
      */
@@ -132,7 +129,8 @@ public interface FdkkClient {
 
     @Post("{url}")
     @Address(source = FdkkSceneAddressSource.class)
-    JSONObject sendPostFile(@Var("url") String url, @Body Map<String,String> param, @DataFile("file") String file, @Header("token")  String token);
+    JSONObject sendPostFile(@Var("url") String url, @Body Map<String,String> param,
+                            @DataFile("file") MultipartFile file, @Header("token")  String token);
 
     @Post("{url}")
     @Address(source = FdkkSceneAddressSource.class)

+ 3 - 18
src/main/java/com/cdf/interceptor/SceneInterceptor.java

@@ -91,25 +91,10 @@ public class SceneInterceptor implements HandlerInterceptor {
 
 				MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
 				Map<String, MultipartFile> fileMap = mRequest.getFileMap();
-				String path = null;
-				if(fileMap.size() >0){
-					for (Map.Entry<String, MultipartFile> next : fileMap.entrySet()) {
-						MultipartFile file = next.getValue();
-						if(file !=null && file.getSize() >0){
-							String fileName = file.getOriginalFilename();
-							assert fileName != null;
-							String num = map.get("num") == null ?"test":map.get("num");
-							String newFilePath = String.format(hotLocalPath,num) + "/"+fileName ;
+				MultipartFile file = fileMap.get("file");
 
-							File newFile = new File(newFilePath);
-							file.transferTo(newFile);
-							path = newFile.getPath();
-						}
-					}
-				}
-
-				if(fileMap.size() >0){
-					send = fdkkClient.sendPostFile(requestURI, map, path,fdkkToken);
+				if(file !=null){
+					send = fdkkClient.sendPostFile(requestURI, map, file,fdkkToken);
 				}else {
 					send = fdkkClient.sendPost(requestURI, map,fdkkToken);
 				}

+ 11 - 7
src/main/java/com/cdf/service/impl/FdkkSceneEditService.java

@@ -154,8 +154,16 @@ public class FdkkSceneEditService {
     }
 
     public FdkkResponse uploadFiles(FdkkUploadRequest fdkkUploadRequest, MultipartFile[] files, String token) throws IOException {
+        List<MultipartFile> multipartFiles = new ArrayList<>();
+        if(StringUtils.isNotBlank(fdkkUploadRequest.getBase64())){
+            MultipartFile file = BASE64DecodedMultipartFile.base64ToMultipart(fdkkUploadRequest.getBase64());
+            multipartFiles.add(file);
+        }
+        if(files.length >0){
+            multipartFiles.addAll(Arrays.asList(files));
+        }
         List<String> paths = new ArrayList<>();
-        for (MultipartFile file : files) {
+        for (MultipartFile file : multipartFiles) {
             if(file !=null && file.getSize() >0){
                 String fileName = file.getOriginalFilename();
                 assert fileName != null;
@@ -166,12 +174,8 @@ public class FdkkSceneEditService {
                 paths.add(path);
             }
         }
-        FdkkResponse fdkkResponse;
-        if(paths.size() >0){
-             fdkkResponse = fdkkClient.uploadFiles(fdkkUploadRequest,paths,fdkkSceneService.getFdkkToken(token));
-        }else {
-             fdkkResponse = fdkkClient.uploadFiles(fdkkUploadRequest,fdkkSceneService.getFdkkToken(token));
-        }
+        fdkkUploadRequest.setBase64(null);
+        FdkkResponse fdkkResponse = fdkkClient.uploadFiles(fdkkUploadRequest,paths,fdkkSceneService.getFdkkToken(token));
         if(fdkkResponse.getCode() !=0){
             throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
         }

+ 81 - 0
src/main/java/com/cdf/util/BASE64DecodedMultipartFile.java

@@ -0,0 +1,81 @@
+package com.cdf.util;
+
+import org.springframework.web.multipart.MultipartFile;
+import sun.misc.BASE64Decoder;
+
+import java.io.*;
+
+public class BASE64DecodedMultipartFile implements MultipartFile {
+    private final byte[] imgContent;
+    private final String header;
+
+    public BASE64DecodedMultipartFile(byte[] imgContent, String header) {
+        this.imgContent = imgContent;
+        this.header = header.split(";")[0];
+    }
+
+    @Override
+    public String getName() {
+        // TODO - implementation depends on your requirements
+        return System.currentTimeMillis() + Math.random() + "." + header.split("/")[1];
+    }
+
+    @Override
+    public String getOriginalFilename() {
+        // TODO - implementation depends on your requirements
+        return System.currentTimeMillis() + (int)Math.random() * 10000 + "." + header.split("/")[1];
+    }
+
+    @Override
+    public String getContentType() {
+        // TODO - implementation depends on your requirements
+        return header.split(":")[1];
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return imgContent == null || imgContent.length == 0;
+    }
+
+    @Override
+    public long getSize() {
+        return imgContent.length;
+    }
+
+    @Override
+    public byte[] getBytes() throws IOException {
+        return imgContent;
+    }
+
+    @Override
+    public InputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream(imgContent);
+    }
+
+    @Override
+    public void transferTo(File dest) throws IOException, IllegalStateException {
+        new FileOutputStream(dest).write(imgContent);
+    }
+
+
+    public static MultipartFile base64ToMultipart(String base64) {
+        try {
+            String[] baseStrs = base64.split(",");
+
+            BASE64Decoder decoder = new BASE64Decoder();
+            byte[] b = new byte[0];
+            b = decoder.decodeBuffer(baseStrs[1]);
+
+            for(int i = 0; i < b.length; ++i) {
+                if (b[i] < 0) {
+                    b[i] += 256;
+                }
+            }
+            return new BASE64DecodedMultipartFile(b, baseStrs[0]);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+}

+ 5 - 5
src/main/resources/application-local.yaml

@@ -3,9 +3,9 @@ spring:
     name: druidDataSource
     type: com.alibaba.druid.pool.DruidDataSource
     druid:
-      url: jdbc:mysql://3.71.48.65:3306/cdf_gm?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true
+      url: jdbc:mysql://127.0.0.1:3306/cdf_gm?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true
       username: root
-      password: 4Dage@zhongmian#@168
+      password: 123456
 logging:
   config: classpath:logback-spring.xml
 mybatis-plus:
@@ -14,8 +14,8 @@ mybatis-plus:
 
 
 fdkk:
-  login-path: http://eur.4dkankan.com
-  scene-path: http://eur.4dkankan.com
+  login-path: http://test.4dkankan.com
+  scene-path: http://v4-test.4dkankan.com
   hot-path: scene_view_data/%s/user/hot.json
   hot-cdf-path: cdf/hot/%s/hot.json
   hot-local-path: D:\temp/%s
@@ -25,7 +25,7 @@ fdkk:
 #    type: aws      亚马逊 s3
 #    type: local    本地化
 upload:
-  type: aws
+  type: oss
   file-path: cdf/file/
   bucket: 4dkankan
   query-path: http://4dkankan.oss-cn-shenzhen.aliyuncs.com/     #oss