优化七牛文件上传,获取token方式
This commit is contained in:
parent
ea9fa88af3
commit
f27665b00b
|
|
@ -20,19 +20,20 @@ import java.io.InputStream;
|
||||||
*/
|
*/
|
||||||
public class QiniuStorageService extends StorageService {
|
public class QiniuStorageService extends StorageService {
|
||||||
private final UploadManager uploadManager;
|
private final UploadManager uploadManager;
|
||||||
private final String token;
|
|
||||||
|
|
||||||
public QiniuStorageService(StorageProperties properties) {
|
public QiniuStorageService(StorageProperties properties) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
|
|
||||||
uploadManager = new UploadManager(new Configuration(Region.autoRegion()));
|
uploadManager = new UploadManager(new Configuration(Region.autoRegion()));
|
||||||
token = Auth.create(properties.getQiniu().getAccessKey(), properties.getQiniu().getSecretKey()).
|
|
||||||
uploadToken(properties.getQiniu().getBucketName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String upload(byte[] data, String path) {
|
public String upload(byte[] data, String path) {
|
||||||
try {
|
try {
|
||||||
|
String token = Auth.create(properties.getQiniu().getAccessKey(), properties.getQiniu().getSecretKey()).
|
||||||
|
uploadToken(properties.getQiniu().getBucketName());
|
||||||
|
|
||||||
Response res = uploadManager.put(data, path, token);
|
Response res = uploadManager.put(data, path, token);
|
||||||
if (!res.isOK()) {
|
if (!res.isOK()) {
|
||||||
throw new ServerException(res.toString());
|
throw new ServerException(res.toString());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user