小编ame*_*kar的帖子

如何在使用 boto3 create_presigned_post 时添加元数据?

create_presigned_post想要将自定义元数据添加到我使用boto3上传的文件中。我正在运行以下代码,但收到 403 响应。下面的代码是从这里借来的。难道我做错了什么?

def create_presigned_post(bucket_name, object_name,
                          fields=None, conditions=None, expiration=3600):

    # Generate a presigned S3 POST URL
    s3_client = boto3.client('s3')
    try:
        response = s3_client.generate_presigned_post(bucket_name,
                                                     object_name,
                                                     Fields=fields,
                                                     Conditions=conditions,
                                                     ExpiresIn=expiration)
    except ClientError as e:
        print(e)
        return None

    # The response contains the presigned URL and required fields
    return response

# Generate a presigned S3 POST URL
object_name = 'test-file.txt'
response = create_presigned_post('temp', object_name, fields={'x-amz-meta-test_key': 'test_val'})

# Demonstrate how another Python program can use the presigned URL to upload a file …
Run Code Online (Sandbox Code Playgroud)

metadata amazon-s3 http-status-code-403 pre-signed-url boto3

3
推荐指数
1
解决办法
2526
查看次数