0006-00000202

更新时间:
复制 MD 格式

Problem description

The value of the policy form field in the request header of a PostObject request is not Base64-encoded.

Causes

The policy form field in a PostObject request has an invalid format, which causes a request error.

Examples

None.

Solutions

To construct a valid policy form field:

  1. Create a UTF-8-encoded policy.

  2. Base64-encode the policy and use the result as the value of the policy form field.

Complete examples:

  • Python

import base64
import json
policy = {
    "expiration": "2023-02-19T13:19:00.000Z",
    "conditions": [
        ["content-length-range", 0, 1048576000]
    ]
}
encoded_policy = base64.b64encode(json.dumps(policy).encode('utf-8'))
  • JavaScript

var policyText = {
    "expiration": "2023-02-18T21:39:00.000Z",
    "conditions": [
    	["content-length-range",  0, 1048576000]
    ]
};

var policyBase64 = Base64.encode(JSON.stringify(policyText))

References