优化七牛文件上传,获取token方式

This commit is contained in:
阿沐 2023-12-06 10:35:10 +08:00
parent ea9fa88af3
commit f27665b00b

View File

@ -20,19 +20,20 @@ import java.io.InputStream;
*/
public class QiniuStorageService extends StorageService {
private final UploadManager uploadManager;
private final String token;
public QiniuStorageService(StorageProperties properties) {
this.properties = properties;
uploadManager = new UploadManager(new Configuration(Region.autoRegion()));
token = Auth.create(properties.getQiniu().getAccessKey(), properties.getQiniu().getSecretKey()).
uploadToken(properties.getQiniu().getBucketName());
}
@Override
public String upload(byte[] data, String path) {
try {
String token = Auth.create(properties.getQiniu().getAccessKey(), properties.getQiniu().getSecretKey()).
uploadToken(properties.getQiniu().getBucketName());
Response res = uploadManager.put(data, path, token);
if (!res.isOK()) {
throw new ServerException(res.toString());