'generate presigned url sse-c s3
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
