Commit fbc94cdd authored by Quxl's avatar Quxl
parents 3e2e9e54 b4b51866
......@@ -95,7 +95,11 @@
<artifactId>aliyun-java-sdk-vod</artifactId>
<version>2.11.6</version>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
......
package com.egolm.film.api.web;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -15,6 +17,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.model.MatchMode;
import com.aliyun.oss.model.PolicyConditions;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
......@@ -43,6 +49,13 @@ public class AliyunApiController {
@Value("${aliyun.sts.accessKeySecret}")
private String accessKeySecret;
@Value("${aliyun.oss.endpoint}")
private String endpoint;
@Value("${aliyun.oss.bucket}")
private String bucket;
@Value("${aliyun.video.templateGroupId}")
private String templateGroupId;
......@@ -146,6 +159,60 @@ public class AliyunApiController {
}
}
@ResponseBody
@ApiOperation("获取OSS上传凭证")
@RequestMapping(value = "/getOssPolicy",method=RequestMethod.GET)
public Object getOssPolicy() {
String host = "//" + bucket + "." + endpoint; // host的格式为 bucketname.endpoint
// callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
//String callbackUrl = "http://88.88.88.88.:8888";
String dir = "film/"; // 用户上传文件时指定的前缀。
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
try {
long expireTime = 30;
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
Date expiration = new Date(expireEndTime);
PolicyConditions policyConds = new PolicyConditions();
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
String postPolicy = client.generatePostPolicy(expiration, policyConds);
byte[] binaryData = postPolicy.getBytes("utf-8");
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
String postSignature = client.calculatePostSignature(postPolicy);
Map<String, String> respMap = new LinkedHashMap<String, String>();
respMap.put("accessid", accessKeyId);
respMap.put("policy", encodedPolicy);
respMap.put("signature", postSignature);
respMap.put("dir", dir);
respMap.put("host", host);
respMap.put("expire", String.valueOf(expireEndTime / 1000));
// respMap.put("expire", formatISO8601Date(expiration));
/*
JSONObject jasonCallback = new JSONObject();
jasonCallback.put("callbackUrl", callbackUrl);
jasonCallback.put("callbackBody",
"filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}");
jasonCallback.put("callbackBodyType", "application/x-www-form-urlencoded");
String base64CallbackBody = BinaryUtil.toBase64String(jasonCallback.toString().getBytes());
respMap.put("callback", base64CallbackBody);
*/
return Rjx.jsonOk().set("detail",respMap);
} catch (Exception e) {
// Assert.fail(e.getMessage());
System.out.println(e.getMessage());
}
return Rjx.jsonErr().setMessage("上传凭证获取失败").toJson();
}
/**
* https://help.aliyun.com/document_detail/52839.html?spm=a2c4g.11186623.2.16.56da9028Qxc5wl#TranscodeTemplate
* @Title: transcode
......@@ -338,4 +405,7 @@ public class AliyunApiController {
return "处理完成";
}
}
......@@ -39,4 +39,7 @@ aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
#\u89C6\u9891\u8F6C\u7801ID
aliyun.video.templateGroupId=d9f4a79cba14ce4cbc98d6516d35bf37
aliyun.video.cateID=1000018495
aliyun.oss.endpoint=oss-cn-shanghai.aliyuncs.com
aliyun.oss.bucket=siff-film-pic
opt.project.type=1
\ No newline at end of file
......@@ -38,4 +38,7 @@ aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
#\u89C6\u9891\u8F6C\u7801ID
aliyun.video.templateGroupId=d9f4a79cba14ce4cbc98d6516d35bf37
aliyun.video.cateID=1000018494
aliyun.oss.endpoint=oss-cn-shanghai.aliyuncs.com
aliyun.oss.bucket=siff-film-pic
opt.project.type=1
\ No newline at end of file
......@@ -38,4 +38,6 @@ aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
#\u89C6\u9891\u8F6C\u7801ID
aliyun.video.templateGroupId=d9f4a79cba14ce4cbc98d6516d35bf37
aliyun.video.cateID=1000018494
aliyun.oss.endpoint=oss-cn-shanghai.aliyuncs.com
aliyun.oss.bucket=siff-film-pic
opt.project.type=1
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment