Browse Source

判断阿里云上传错误url

qianxb 2 years ago
parent
commit
3797bd9317

+ 7 - 3
blade-common/src/main/java/org/springblade/common/utils/CommonUtil.java

@@ -94,9 +94,13 @@ public class CommonUtil {
     public static InputStream getOSSInputStream(String urlStr) throws Exception {
         //获取OSS文件流
         URL imageUrl = new URL(urlStr);
-        HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
-        conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
-        return conn.getInputStream();
+        try {
+            HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
+            conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
+            return conn.getInputStream();
+        }catch (Exception e){
+            return null;
+        }
     }
 
     /**

+ 8 - 4
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveOfflineVersionInfoServiceImpl.java

@@ -88,15 +88,19 @@ public class ArchiveOfflineVersionInfoServiceImpl extends BaseServiceImpl<Archiv
                     String fileUrl = file.getFileUrl();
                     String fileName = fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
                     InputStream file_out = CommonUtil.getOSSInputStream(fileUrl);
-                    CommonUtil.inputStreamToFile(file_out, new File(localUrl + fileName));
-                    file.setFileUrl(fileName);
+                    if (file_out != null) {
+                        CommonUtil.inputStreamToFile(file_out, new File(localUrl + fileName));
+                        file.setFileUrl(fileName);
+                    }
                 }
                 if (StringUtil.isNotBlank(file.getPdfFileUrl())) {
                     String pdfFileUrl = file.getPdfFileUrl();
                     String fileName = pdfFileUrl.substring(pdfFileUrl.lastIndexOf('/') + 1);
                     InputStream file_out = CommonUtil.getOSSInputStream(pdfFileUrl);
-                    CommonUtil.inputStreamToFile(file_out, new File(localUrl + fileName));
-                    file.setPdfFileUrl(fileName);
+                    if (file_out != null) {
+                        CommonUtil.inputStreamToFile(file_out, new File(localUrl + fileName));
+                        file.setPdfFileUrl(fileName);
+                    }
                 }
             }
             try {