You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用预签名POST URL上传S3时出现InvalidPolicyDocument错误

解决S3 POST预签名URL上传时的InvalidPolicyDocument错误

上传时返回的错误:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>InvalidPolicyDocument</Code>
    <Message>Invalid Policy: Invalid JSON.</Message>
    <RequestId>568TTY4KHP1SR41W</RequestId>
    <HostId>Fk5dAEIEM2Awp2+JPpuD60karubosk5crAcYCejtSZkLsyqPdFEmh4GVSEv3+tIeYSc78/OY6JY=</HostId>
</Error>

问题根源

解码后的Policy文档中,content-length-range条件的上限值是512.0(浮点数),但AWS S3要求该条件的两个参数必须是整数,不能使用小数形式,这直接导致了JSON格式校验失败。

修复步骤

  1. 修改Policy中的content-length-range条件,将浮点数512.0改为整数512:
    {
      "expiration": "2023-12-13T05:29:22.211Z",
      "conditions": [
        { "bucket": "<valid bucket name>" },
        { "x-amz-credential": "<valid cred id>/20231212/eu-west-2/s3/aws4_request" },
        { "x-amz-algorithm": "AWS4-HMAC-SHA256" },
        { "x-amz-date": "20231212T052922Z" },
        ["starts-with", "$x-amz-meta-record-type", ""],
        ["starts-with", "$x-amz-meta-record-name", ""],
        ["starts-with", "$x-amz-meta-record-expiration", "2023-12-19T06:29:22.211681+01:00"],
        ["eq", "$x-amz-meta-author-tier", "tier:0"],
        ["eq", "$x-amz-meta-author", "e2b1bffb-909b-4e22-8662-7596ce7c4e17"],
        ["eq", "$key", "e2b1bffb-909b-4e22-8662-7596ce7c4e17/f406f897-f6bb-42c9-a4bc-e48f257cf260"],
        ["content-length-range", 0, 512]
      ]
    }
    
  2. 重新对修改后的Policy进行Base64编码,替换POST表单中的policy字段值后重新尝试上传。

内容的提问来源于stack exchange,提问作者chandler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:15:04