1
0
Prechádzať zdrojové kódy

修改又拍云模拟文件接口

1.放开部分又拍云内嵌字段名
2.增加head接口返回md5信息
luoshi 6 rokov pred
rodič
commit
ad18a8a17b

+ 3 - 3
stmms-common/src/main/java/cn/com/qmth/stmms/common/upyun/UpYun.java

@@ -56,11 +56,11 @@ public class UpYun {
 
     private final String X_UPYUN_FRAMES = "x-upyun-frames";
 
-    private final String X_UPYUN_FILE_TYPE = "x-upyun-file-type";
+    public static final String X_UPYUN_FILE_TYPE = "x-upyun-file-type";
 
-    private final String X_UPYUN_FILE_SIZE = "x-upyun-file-size";
+    public static final String X_UPYUN_FILE_SIZE = "x-upyun-file-size";
 
-    private final String X_UPYUN_FILE_DATE = "x-upyun-file-date";
+    public static final String X_UPYUN_FILE_DATE = "x-upyun-file-date";
 
     private final String METHOD_HEAD = "HEAD";
 

+ 7 - 5
stmms-web/src/main/java/cn/com/qmth/stmms/file/controller/FileController.java

@@ -14,7 +14,6 @@ import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
-import org.springframework.util.FileCopyUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
@@ -76,7 +75,7 @@ public class FileController implements InitializingBean {
         File full = new File(baseDir, filePath);
         if (full.exists()) {
             try {
-                FileCopyUtils.copy(new FileInputStream(full), response.getOutputStream());
+                IOUtils.copy(new FileInputStream(full), response.getOutputStream());
             } catch (Exception e) {
                 response.sendError(500, "read file faile: " + full.getAbsolutePath());
             }
@@ -96,9 +95,12 @@ public class FileController implements InitializingBean {
         File full = new File(baseDir, filePath);
         if (full.exists()) {
             try {
-                response.addHeader("x-upyun-file-type", full.isFile() ? "file" : "folder");
-                response.addHeader("x-upyun-file-size", String.valueOf(full.length()));
-                response.addHeader("x-upyun-file-date", String.valueOf(full.lastModified()));
+                response.addHeader(UpYun.X_UPYUN_FILE_TYPE, full.isFile() ? "file" : "folder");
+                response.addHeader(UpYun.X_UPYUN_FILE_SIZE, String.valueOf(full.length()));
+                response.addHeader(UpYun.X_UPYUN_FILE_DATE, String.valueOf(full.lastModified()));
+                if (full.isFile()) {
+                    response.addHeader(UpYun.CONTENT_MD5, UpYun.md5(full));
+                }
             } catch (Exception e) {
                 response.sendError(500, "read file faile: " + full.getAbsolutePath());
             }