Skip to content

Commit 7b73d11

Browse files
colorful3juzi214032
authored andcommitted
fix: 修复由于只在 sevlet 加载时获取七牛 token 导致的文件上传时 token 过期的 bug
1 parent 71277f4 commit 7b73d11

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

src/main/java/io/github/talelin/latticy/extension/file/QiniuUploader.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
import io.github.talelin.latticy.module.file.AbstractUploader;
1010
import io.github.talelin.latticy.module.file.FileConstant;
1111
import io.github.talelin.latticy.module.file.FileProperties;
12-
import org.springframework.beans.factory.annotation.Autowired;
1312
import lombok.extern.slf4j.Slf4j;
13+
import org.springframework.beans.factory.annotation.Autowired;
1414
import org.springframework.beans.factory.annotation.Value;
1515

16-
import javax.annotation.PostConstruct;
1716
import java.io.ByteArrayInputStream;
1817

1918
/**
2019
* 文件上传服务实现,上传到七牛
2120
*
2221
* @author pedro@TaleLin
22+
* @author colorful@TaleLin
2323
*/
2424
@Slf4j
2525
public class QiniuUploader extends AbstractUploader {
@@ -40,11 +40,6 @@ public class QiniuUploader extends AbstractUploader {
4040

4141
private String upToken;
4242

43-
/**
44-
* 因为需要得到 spring-boot 提供的配置,所以不能在 constructor 中初始化
45-
* 使用 PostConstruct 来初始化
46-
*/
47-
@PostConstruct
4843
public void initUploadManager() {
4944
Configuration cfg = new Configuration(Region.region2());
5045
uploadManager = new UploadManager(cfg);
@@ -76,6 +71,7 @@ protected String getFileType() {
7671
*/
7772
@Override
7873
protected boolean handleOneFile(byte[] bytes, String newFilename) {
74+
initUploadManager();
7975
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);
8076
try {
8177
Response response = uploadManager.put(byteInputStream, newFilename, upToken, null, null);

0 commit comments

Comments
 (0)