From 57df7f8dfe2b1ea4f3d0cb542d5d6d258be54f91 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期一, 08 十一月 2021 14:36:07 +0800
Subject: [PATCH] fix 修复 OSS 七牛云 token 过期未刷新问题
---
ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java | 12 ++++++------
1 files 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 e9b8dc0..0c23e76 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 @@
private UploadManager uploadManager;
private BucketManager bucketManager;
- private String token;
+ private Auth auth;
@Override
public void init(CloudStorageProperties cloudStorageProperties) {
@@ -35,9 +35,8 @@
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 @@
@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 @@
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());
--
Gitblit v1.9.3