use of com.qiniu.storage.UploadManager in project paascloud-master by paascloud.
the class QiniuOssConfiguration method uploadManager.
/**
* Upload manager upload manager.
*
* @return the upload manager
*/
@Bean
public UploadManager uploadManager() {
Zone zone = Zone.autoZone();
// 创建上传对象
UploadManager uploadManager = new UploadManager(new com.qiniu.storage.Configuration(zone));
log.info("Create UploadManager OK.");
return uploadManager;
}
use of com.qiniu.storage.UploadManager in project xmall by Exrick.
the class QiniuUtil method qiniuUpload.
public static String qiniuUpload(String filePath) {
// 构造一个带指定Zone对象的配置类 zone2华南
Configuration cfg = new Configuration(Zone.zone2());
UploadManager uploadManager = new UploadManager(cfg);
String localFilePath = filePath;
// 默认不指定key的情况下,以文件内容的hash值作为文件名
String key = null;
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
try {
Response response = uploadManager.put(localFilePath, key, upToken);
// 解析上传成功的结果
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
return origin + putRet.key;
} catch (QiniuException ex) {
Response r = ex.response;
log.warn(r.toString());
try {
log.warn(r.bodyString());
return r.bodyString();
} catch (QiniuException ex2) {
// ignore
}
}
return null;
}
Aggregations