【问题标题】:presigned URL : Post image error: Signature does not match: Python预签名 URL:发布图像错误:签名不匹配:Python
【发布时间】:2023-04-01 02:58:02
【问题描述】:
  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,我就会尝试从邮递员那里发布图片

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

【问题讨论】:

标签: python amazon-web-services amazon-s3 aws-lambda pre-signed-url


【解决方案1】:

尝试从Params 中删除ACLContent-Type。这些不适用于generate_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 方法。

【讨论】:

    【解决方案2】:

    Checkout thisGitHub 链接(如果创建预签名 URL 用于上传)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-09
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      相关资源
      最近更新 更多