BOTO3 - generate_presigned_url for `put_object` return `The request signature we calculated does not match the signature you provided`

后端 未结 2 489
后悔当初
后悔当初 2021-01-20 04:50

I\'m trying to create a presigned url that will help some customers to upload files . Here my test script that is currently working

# Get the service client.         


        
相关标签:
2条回答
  • 2021-01-20 05:17

    Got the same problem using S3 on Dell ECS object storage. The S3 protocol is implemented partially so there's no support for POST method with ECS. The workaround is to use correct headers in PUT methtod, then the ACL for the object are set correctly on the server.

        # Get the service client.
        s3 = boto3.client('s3')
        boto3.set_stream_logger(name='botocore')
    
        # Generate the URL to get 'key-name' from 'bucket-name'
        url = s3.generate_presigned_url(
            ClientMethod='put_object',
            Params={
                'Bucket': s3_bucket_name,
                'Key': test_key,
                'ACL': 'public-read'
            }    
        )
    
        files = StringIO("asdfasdfasdf")
        headers = {'x-amz-acl': 'public-read'}
        response = requests.put(url, data=files, headers=headers)
    
        print(str(response.content))
    
    0 讨论(0)
  • 2021-01-20 05:22

    This is covered in the github issue https://github.com/boto/boto3/issues/934

    For uploading an object, you should use generate_presigned_post. There are several parameters that cannot be embedded within the url, and those are returned to you by that method.

    0 讨论(0)
提交回复
热议问题