|
@@ -115,4 +115,31 @@ public class OSSUtil {
|
|
return resultUrl;
|
|
return resultUrl;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public Map<String, String> getConfig() throws UnsupportedEncodingException {
|
|
|
|
+ OSS client = buildClient();
|
|
|
|
+ String host = "https://" + OSS_BUCKET_NAME + "." + OSS_ENDPOINT_WW; // host的格式为 bucketname.endpoint
|
|
|
|
+
|
|
|
|
+// OSSClient client = new OSSClient(endpoint, accessId, accessKey);
|
|
|
|
+ long expireTime = 300;
|
|
|
|
+ long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
|
|
|
+ java.sql.Date expiration = new java.sql.Date(expireEndTime);
|
|
|
|
+ PolicyConditions policyConds = new PolicyConditions();
|
|
|
|
+ policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);
|
|
|
|
+ policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, getFilePath());
|
|
|
|
+
|
|
|
|
+ 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("OSSAccessKeyId", ACCESS_KEY_ID);
|
|
|
|
+ respMap.put("expire", String.valueOf(expireEndTime / 1000));
|
|
|
|
+ respMap.put("policy", encodedPolicy);
|
|
|
|
+ respMap.put("signature", postSignature);
|
|
|
|
+ respMap.put("id", ACCESS_KEY_ID);
|
|
|
|
+ respMap.put("dir", getFilePath()+"/");
|
|
|
|
+ respMap.put("host", host);
|
|
|
|
+ return respMap;
|
|
|
|
+ }
|
|
}
|
|
}
|