生成预签名 url sse-c s3
在Python中使用SSE-C
时,如何生成预签名url
来获取对象的URL?
当我上传文件时,这就是我的代码现在的样子
secret = '?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf' # just pasting here. In general, it's usually derived from .env file
return client.put_object(
Bucket=os.environ.get('S3_DOCS_BUCKET'),
Key='koushik.jpg', # giving a random name for .jpg image file
Body=file,
ContentType=fileobject.content_type,
SSECustomerAlgorithm='AES256',
SSECustomerKey=secret,
)
,上传得很好。但问题是我无法生成这样的预签名 URL
url = client.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': os.environ.get('S3_DOCS_BUCKET'),
'Key': 'koushik.jpg',
'SSECustomerAlgorithm': 'AES256',
'SSECustomerKey': '?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf', # just pasting here
},
ExpiresIn=3600,
)
它生成的密钥表示签名不匹配。 现在我搜索过,在某些地方,它说我还必须提供 SSECustomerKeyMD5
参数。 我已经尝试这样做了,但仍然不起作用。
url = client.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': os.environ.get('S3_DOCS_BUCKET'),
'Key': 'koushik.jpg',
'SSECustomerAlgorithm': 'AES256',
'SSECustomerKey': '?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf', # just pasting here,
'SSECustomerKeyMD5': hashlib.md5('?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf'.encode('utf-8')).hexdigest()
},
ExpiresIn=3600,
)
我已经花了几天时间但仍然无法找到有效的解决方案。 如果有人可以,请通过提供 SSECustomerKeyMD5
来展示文件上传(又名 put_object)
的工作示例。我认为这会对我有很大帮助。先感谢您。
How to generate a presigned url
to get an URL to an object using when SSE-C
is used in python?
When I upload the file, this is what my code looks like
secret = '?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf' # just pasting here. In general, it's usually derived from .env file
return client.put_object(
Bucket=os.environ.get('S3_DOCS_BUCKET'),
Key='koushik.jpg', # giving a random name for .jpg image file
Body=file,
ContentType=fileobject.content_type,
SSECustomerAlgorithm='AES256',
SSECustomerKey=secret,
)
Now, this uploads fine. But the problem is that I can't generate pre signed URL like this
url = client.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': os.environ.get('S3_DOCS_BUCKET'),
'Key': 'koushik.jpg',
'SSECustomerAlgorithm': 'AES256',
'SSECustomerKey': '?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf', # just pasting here
},
ExpiresIn=3600,
)
The key that it generates says that the signature doesn't match.
Now I've searched, at some places, it says that I've to provide the SSECustomerKeyMD5
params as well.
I've tried doing that and still doesn't work.
url = client.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': os.environ.get('S3_DOCS_BUCKET'),
'Key': 'koushik.jpg',
'SSECustomerAlgorithm': 'AES256',
'SSECustomerKey': '?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf', # just pasting here,
'SSECustomerKeyMD5': hashlib.md5('?D(G+KbPeSgVkYp3s6v9y$B&E)H@McQf'.encode('utf-8')).hexdigest()
},
ExpiresIn=3600,
)
I've spent days but still can't get a working solution.
If anyone can, please show an working example of file upload(a.k.a put_object)
by providing SSECustomerKeyMD5
. I think that would help me a lot. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论