优化七牛文件上传,获取token方式
This commit is contained in:
parent
ea9fa88af3
commit
f27665b00b
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user