Invalid according to Policy: Policy expired.

¥10.00

小程序直传OSS时报错:

Object {cookies: Array[0], data: "
cookies: Array[0]
data: "AccessDenied Invalid according to Policy: Policy expired.5FE30C24CB3DB13837E8A03Fhrncardvideo.oss-cn-beijing.aliyuncs.com"
errMsg: "uploadFile:ok"
header: Object
statusCode: 403
__proto__: Object

服务端签名代码:

public static string GetEncodedPolicy(int maxSize,string startWith)
        {
            if (maxSize==0)
            {
                maxSize = 20 * 1024 * 1024;//20M
            }
            // 创建OssClient实例。
            var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
            DateTime now = DateTime.Now;
            DateTime ex = now.AddSeconds(15);
            PolicyConditions policyConds = new PolicyConditions();
            //policyConds.AddConditionItem("content-length-range", 0L, 1048576000L);
            policyConds.AddConditionItem("content-length-range", 0L, maxSize);
            policyConds.AddConditionItem(MatchMode.StartWith, "key", startWith);
            string postPolicy = client.GeneratePostPolicy(ex, policyConds);
            byte[] binaryData = Encoding.Default.GetBytes(postPolicy);
            string encodedPolicy = Convert.ToBase64String(binaryData);
            return encodedPolicy;
        }


UMU T0 发布于4个月前

最佳解决方案

原因分析

签名过期了,时效15秒,调大些就可以了

前面代码改为:

public static string GetEncodedPolicy(int maxSize,string startWith)
        {
            if (maxSize==0)
            {
                maxSize = 20 * 1024 * 1024;//20M
            }
            // 创建OssClient实例。
            var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
            DateTime now = DateTime.Now;
            DateTime ex = now.AddSeconds(15*60);
            PolicyConditions policyConds = new PolicyConditions();
            //policyConds.AddConditionItem("content-length-range", 0L, 1048576000L);
            policyConds.AddConditionItem("content-length-range", 0L, maxSize);
            policyConds.AddConditionItem(MatchMode.StartWith, "key", startWith);
            string postPolicy = client.GeneratePostPolicy(ex, policyConds);
            byte[] binaryData = Encoding.Default.GetBytes(postPolicy);
            string encodedPolicy = Convert.ToBase64String(binaryData);
            return encodedPolicy;
        }


田田 T1 被采纳率33%
2020-12-23 17:35
打赏 0 0
页面统计
620 访问
0 帮助
0.00 打赏

hierror 2019 © hierror.com 京ICP备13026190号-1

通知消息
  • 暂无任何消息