Luc*_*uca 5 python amazon-s3 amazon-web-services boto3
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.
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,
}
)
files = StringIO("asdfasdfasdf")
response = requests.put(url, data=files)
print(str(response.content))
Run Code Online (Sandbox Code Playgroud)
But if I'm adding:
`ACL': 'public-read'
Run Code Online (Sandbox Code Playgroud)
to Params (or add some metadata following the information in the put_object documentation I receive back from the server:
The request signature we calculated does not match the signature you provided. Check your key and signing method.
Run Code Online (Sandbox Code Playgroud)
I've open also a issue on BOTO3: https://github.com/boto/boto3/issues/1722
小智 9
在 Dell ECS 对象存储上使用 S3 时遇到同样的问题。S3 协议已部分实现,因此不支持 ECS 的 POST 方法。解决方法是在 PUT 方法中使用正确的标头,然后在服务器上正确设置对象的 ACL。
# 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))
Run Code Online (Sandbox Code Playgroud)
这在 github 问题https://github.com/boto/boto3/issues/934 中有介绍
要上传对象,您应该使用generate_presigned_post。有几个参数不能嵌入到 url 中,这些参数会通过该方法返回给您。
| 归档时间: |
|
| 查看次数: |
8898 次 |
| 最近记录: |