生成预签名 url sse-c s3

发布于 2025-01-11 15:47:04 字数 1673 浏览 0 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文