77777
This commit is contained in:
parent
a8186b34f7
commit
e21e28e3f9
@ -71,4 +71,35 @@ public class OSSFileController {
|
||||
return ResponseDTO.userErrorParam();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取上传文件 Policy ", notes="type==1 普通;type==2 签名图片")
|
||||
@GetMapping("/file/getOSSPolicy/admin/{type}")
|
||||
public ResponseDTO<OSSPolicyVO> getOSSPolicyAdmin(@PathVariable int type){
|
||||
OSSFileTypeEnum ossFileType = OSSFileTypeEnum.getByVal(type);
|
||||
Long requestUserId = SmartRequestUtil.getRequestUserId();
|
||||
String dir = ossFileType.getDesc() + File.separator + "images/";
|
||||
// String dir = ossFileType.getDesc() + File.separator + requestUserId + File.separator;
|
||||
// callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
|
||||
OSSClient client = new OSSClient(endpoint, accessKey, secretKey);
|
||||
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, 10*1024*1024);// 最大 10 M
|
||||
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, ossFileType.getDesc());
|
||||
|
||||
String postPolicy = client.generatePostPolicy(expiration, policyConds);
|
||||
byte[] binaryData = postPolicy.getBytes("utf-8");
|
||||
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
|
||||
String postSignature = client.calculatePostSignature(postPolicy);
|
||||
|
||||
|
||||
OSSPolicyVO policyVO = new OSSPolicyVO(accessKey, encodedPolicy, postSignature, dir, host, String.valueOf(expireEndTime / 1000));
|
||||
return ResponseDTO.ok(policyVO);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseDTO.userErrorParam();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user