Browse Source

上传错误提醒1

wuweihao 3 years ago
parent
commit
ca8b3ad07d
1 changed files with 17 additions and 9 deletions
  1. 17 9
      gis_common/src/main/java/com/gis/common/util/QiniuOssUtil.java

+ 17 - 9
gis_common/src/main/java/com/gis/common/util/QiniuOssUtil.java

@@ -1,5 +1,7 @@
 package com.gis.common.util;
 
+import com.alibaba.fastjson.JSONObject;
+import com.gis.common.exception.BaseRuntimeException;
 import com.google.gson.Gson;
 import com.qiniu.common.QiniuException;
 import com.qiniu.common.Zone;
@@ -55,7 +57,21 @@ public class QiniuOssUtil {
         // 覆盖需要把ossKey放到uploadToken里
         String upToken = auth.uploadToken(bucketName, ossFilePath);
         Response response = uploadManager.put(localFilePath, ossFilePath, upToken);
-        log.info("七牛云响应值:{}", response.toString());
+        if (response.statusCode!=200){
+            String errorMsg = response.toString();
+            log.error("七牛云响应值:{}", errorMsg);
+            BaseRuntimeException.isTrue(true, null, "七牛云返回上传失败: " + errorMsg);
+        }
+    }
+
+
+    public static void main(String[] args) throws QiniuException {
+        String localFilePath = "F:\\test\\ngin\\11.txt";
+        String ossFilePath = "data/owen/11.txt";
+        upload(localFilePath, ossFilePath);
+        System.out.println("11111");
+
+//        getInfo(ossFilePath);
     }
 
 
@@ -122,14 +138,6 @@ public class QiniuOssUtil {
         }
     }
 
-    public static void main(String[] args) throws QiniuException {
-        String localFilePath = "F:\\test\\ngin\\11.txt";
-        String ossFilePath = "data/owen/11.txt";
-        upload(localFilePath, ossFilePath);
-        System.out.println("11111");
-
-//        getInfo(ossFilePath);
-    }
 
     /**
      * 测试demo