...
|
...
|
@@ -4,9 +4,11 @@ import com.qiniu.common.QiniuException; |
|
|
import com.qiniu.common.Zone;
|
|
|
import com.qiniu.http.Response;
|
|
|
import com.qiniu.processing.OperationManager;
|
|
|
import com.qiniu.processing.OperationStatus;
|
|
|
import com.qiniu.storage.BucketManager;
|
|
|
import com.qiniu.storage.Configuration;
|
|
|
import com.qiniu.storage.UploadManager;
|
|
|
import com.qiniu.storage.model.DefaultPutRet;
|
|
|
import com.qiniu.storage.model.FetchRet;
|
|
|
import com.qiniu.util.Auth;
|
|
|
import com.qiniu.util.StringMap;
|
|
|
import com.qiniu.util.UrlSafeBase64;
|
...
|
...
|
@@ -37,6 +39,8 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
// 用于七牛云上传的bucket
|
|
|
private Map<String, String> bucketList;
|
|
|
|
|
|
private static final Configuration cfg = new Configuration(Zone.zone0());
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
auth = Auth.create(accessKey, secretKey);
|
...
|
...
|
@@ -76,7 +80,7 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
//Configuration c = new Configuration(z);
|
|
|
|
|
|
//实例化一个BucketManager对象
|
|
|
BucketManager bucketManager = new BucketManager(auth);
|
|
|
BucketManager bucketManager = new BucketManager(auth, cfg);
|
|
|
|
|
|
//文件保存的空间名和文件名
|
|
|
String bucket = "yhb-img01";
|
...
|
...
|
@@ -87,7 +91,7 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
|
|
|
try {
|
|
|
//调用fetch方法抓取文件
|
|
|
DefaultPutRet fetch = bucketManager.fetch(url, bucket, key);
|
|
|
FetchRet fetch = bucketManager.fetch(url, bucket, key);
|
|
|
|
|
|
//fetch.
|
|
|
|
...
|
...
|
@@ -106,7 +110,7 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
String SECRET_KEY = "pyoJzPygXIkFWrc1BAsH6tAJ0yweTchpJwGKEwhm";
|
|
|
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
|
|
|
//新建一个OperationManager对象
|
|
|
OperationManager operater = new OperationManager(auth);
|
|
|
OperationManager operater = new OperationManager(auth, cfg);
|
|
|
//设置要转码的空间和key,并且这个key在你空间中存在
|
|
|
String bucket = "yhb-img01";
|
|
|
String key = "ufo/live/m3u8/yohotest14.m3u8"; // 14 4 分钟 15 3分钟
|
...
|
...
|
@@ -119,12 +123,17 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
//可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
|
|
|
String urlbase64 = UrlSafeBase64.encodeToString("yhb-img01:ufo/live/mp4/test25.mp4");
|
|
|
String pfops = fops + "|saveas/" + urlbase64;
|
|
|
//设置pipeline参数
|
|
|
//设置pipeline参数 http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/live/ufo_avthumb_notify
|
|
|
StringMap params = new StringMap().putWhen("force", 1, true).putNotEmpty("pipeline", pipeline);//.put("notifyURL", "http://testapi.yohops.com/live/ufo_avthumb_notify");
|
|
|
try {
|
|
|
String persistid = operater.pfop(bucket, key, pfops, params);
|
|
|
//打印返回的persistid
|
|
|
System.out.println(persistid);
|
|
|
|
|
|
OperationStatus operationStatus = operater.prefop(persistid);
|
|
|
|
|
|
System.out.println(operationStatus.code);
|
|
|
|
|
|
} catch (QiniuException e) {
|
|
|
//捕获异常信息
|
|
|
Response r = e.response;
|
...
|
...
|
@@ -137,6 +146,8 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
//ignore
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public String getToken(String bucket) {
|
...
|
...
|
@@ -150,7 +161,7 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
String fileMode = fileName.substring(15, 17);
|
|
|
|
|
|
String key = bucket + fileName;
|
|
|
UploadManager uploadManager = new UploadManager();
|
|
|
UploadManager uploadManager = new UploadManager(cfg);
|
|
|
Response res;
|
|
|
try {
|
|
|
res = uploadManager.put(file, key, getToken(bucketList.get(fileMode)));
|
...
|
...
|
@@ -173,7 +184,7 @@ public class QNUploadServiceImpl implements IQNUploadService { |
|
|
|
|
|
@Override
|
|
|
public void copyFile(String from_bucket, String from_key, String to_bucket, String to_key) {
|
|
|
BucketManager bucketManager = new BucketManager(auth);
|
|
|
BucketManager bucketManager = new BucketManager(auth, cfg);
|
|
|
try {
|
|
|
bucketManager.copy(from_bucket, from_key, to_bucket, to_key);
|
|
|
} catch (QiniuException e) {
|
...
|
...
|
|