Bladeren bron

update oss

deason 2 jaren geleden
bovenliggende
commit
630f1684f0

+ 2 - 2
examcloud-support/src/test/java/cn/com/qmth/examcloud/support/test/OssClientTest.java

@@ -34,8 +34,8 @@ public class OssClientTest {
         File file = new File(dir + "/abc.png");
 
         final String ossFilePath = "/test/abc.png";
-        // ossClient.upload(file, ossFilePath, false);
-        // System.out.println(ossClient.getProperties().getAliyunDomain() + ossFilePath);
+        // String fileUrl = ossClient.upload(file, ossFilePath, false);
+        // System.out.println(fileUrl);
 
         File toFile = new File(dir + "/abc-new.png");
         // ossClient.download(ossFilePath, toFile);

+ 12 - 9
examcloud-web/src/main/java/cn/com/qmth/examcloud/web/aliyun/OssClient.java

@@ -50,8 +50,8 @@ public class OssClient {
 
             return ossFileUrl;
         } catch (Exception e) {
-            log.error("OSS文件上传异常!{}", e.getMessage());
-            throw new StatusException("OSS文件上传异常!");
+            log.error("文件上传异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+            throw new StatusException("文件上传异常!");
         } finally {
             try {
                 ossClient.shutdown();
@@ -79,8 +79,8 @@ public class OssClient {
 
             return ossFileUrl;
         } catch (Exception e) {
-            log.error("OSS文件上传异常!{}", e.getMessage());
-            throw new StatusException("OSS文件上传异常!");
+            log.error("文件上传异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+            throw new StatusException("文件上传异常!");
         } finally {
             try {
                 ossClient.shutdown();
@@ -98,8 +98,8 @@ public class OssClient {
             GetObjectRequest request = new GetObjectRequest(properties.getAliyunBucketName(), ossFilePath);
             ossClient.getObject(request, toFile);
         } catch (Exception e) {
-            log.error("OSS文件下载异常!{}", e.getMessage());
-            throw new StatusException("OSS文件下载异常!");
+            log.error("文件下载异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+            throw new StatusException("文件下载异常!");
         } finally {
             try {
                 ossClient.shutdown();
@@ -132,8 +132,8 @@ public class OssClient {
 
             return bos.toByteArray();
         } catch (Exception e) {
-            log.error("OSS文件下载异常!{}", e.getMessage());
-            throw new StatusException("OSS文件下载异常!");
+            log.error("文件下载异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+            throw new StatusException("文件下载异常!");
         } finally {
             try {
                 ossClient.shutdown();
@@ -156,7 +156,10 @@ public class OssClient {
      * 3、每秒最多50次请求
      */
     public void refreshCDNCache(String ossFileUrls) {
-        DefaultProfile profile = DefaultProfile.getProfile("oss-cn-shenzhen",
+        // 默认OSS区域ID,注意要和“外网Endpoint”保持一致(后续改为可配置!)
+        final String regionId = "oss-cn-shenzhen";
+
+        DefaultProfile profile = DefaultProfile.getProfile(regionId,
                 properties.getAccessKeyId(), properties.getAccessKeySecret());
         IAcsClient client = new DefaultAcsClient(profile);