From 57df7f8dfe2b1ea4f3d0cb542d5d6d258be54f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 8 Nov 2021 14:36:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20OSS=20=E4=B8=83?= =?UTF-8?q?=E7=89=9B=E4=BA=91=20token=20=E8=BF=87=E6=9C=9F=E6=9C=AA?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oss/service/impl/QiniuCloudStorageStrategy.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java index e9b8dc09..0c23e761 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java @@ -24,7 +24,7 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { private UploadManager uploadManager; private BucketManager bucketManager; - private String token; + private Auth auth; @Override public void init(CloudStorageProperties cloudStorageProperties) { @@ -35,9 +35,8 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { config.useHttpsDomains = false; config.useHttpsDomains = "Y".equals(properties.getIsHttps()); uploadManager = new UploadManager(config); - Auth auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); + auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); String bucketName = properties.getBucketName(); - token = auth.uploadToken(bucketName); bucketManager = new BucketManager(auth, config); if (!ArrayUtil.contains(bucketManager.buckets(), bucketName)) { @@ -69,9 +68,10 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { @Override public UploadResult upload(byte[] data, String path, String contentType) { try { - Response res = uploadManager.put(data, path, token, null, contentType, false); + String token = auth.uploadToken(properties.getBucketName()); + Response res = uploadManager.put(data, path, token, null, contentType, false); if (!res.isOK()) { - throw new RuntimeException("上传七牛出错:" + res.toString()); + throw new RuntimeException("上传七牛出错:" + res.error); } } catch (Exception e) { throw new OssException("上传文件失败,请核对七牛配置信息:[" + e.getMessage() + "]"); @@ -85,7 +85,7 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { path = path.replace(getEndpointLink() + "/", ""); Response res = bucketManager.delete(properties.getBucketName(), path); if (!res.isOK()) { - throw new RuntimeException("删除七牛文件出错:" + res.toString()); + throw new RuntimeException("删除七牛文件出错:" + res.error); } } catch (Exception e) { throw new OssException(e.getMessage());