首页 > 解决方案 > 预签名 URL:发布图像错误:签名不匹配:Python

问题描述

  1. 我将在 lambda 中执行以下命令以生成预签名 URL

'''

import boto3
from botocore.client import Config
def lambda_handler(event, context):
    s3 = boto3.client('s3', config=Config(signature_version='s3v4'))
    url = s3.generate_presigned_url(
        'put_object',
        Params={
            'Bucket': 'XXX-profile',
            'Key': 'test',
            'ContentType': 'image/jpeg',
             'ACL': 'public-read'},
        ExpiresIn=600
    )
    return url 

''' 2. 一旦我得到 URL,我就会尝试从邮递员那里发布图片 在此处输入图像描述

你能帮忙看看我的错误在哪里吗..我找不到。

标签: pythonamazon-web-servicesamazon-s3aws-lambdapre-signed-url

解决方案


尝试从. ACL_ 这些不适用于方法。Content-TypeParamsgenerate_presigned_url

import boto3
from botocore.client import Config
def lambda_handler(event, context):
    s3 = boto3.client('s3', config=Config(signature_version='s3v4'))
    url = s3.generate_presigned_url(
        'put_object',
        Params={
            'Bucket': 'XXX-profile',
            'Key': 'test',
            },
        ExpiresIn=600
    )
    return url 

如果还想设置 content-type 和 ACL,请尝试使用该generate_presigned_post方法。


推荐阅读