python-3.x - 在 python 中为 S3 文件夹创建预签名 URL
问题描述
我正在尝试为 S3 文件夹(它本身包含更多文件夹/文件)生成一个预签名的 url,并将其分发给我的客户,以便他们可以下载其内容。即通过单击链接,用户将文件夹下载到他们的本地磁盘。
但是,我在 XML 对话中不断收到“没有这样的键”错误。
我正在使用来自 boto3 sdk 的 client.generate_presigned_url()
def create_presigned_url(bucket, object):
try:
url = s3_client.generate_presigned_url(
'get_object',
Params={
'Bucket': bucket,
'Key': object
},
ExpiresIn=240,
HttpMethod='GET'
)
except ClientError as e:
print(e)
return None
return url
这是错误消息:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>output/BARNES/070419/APR19BAR/</Key>
<RequestId>E6BE736FE945FA22</RequestId>
<HostId>
hk3+d+***********************************************************+EO2CZmo=
</HostId>
</Error>
解决方案
S3 没有“文件夹”的概念。您在这里有效地尝试做的是为多个键创建一个预签名的 url,这也是不可能的。如果您绝对必须为多个文件共享单个 url,则需要将它们压缩到单个对象中,然后使用预签名 url 共享该对象的密钥。
推荐阅读
- html - 怎么做
标签响应? - wordpress - 使用函数或 htaccess 将特定 url 更改为 wordpress 中的其他 url
- spring-boot - 资源和 ControllerLinkBuilder 未找到且已弃用
- php - 如何在 Jquery 中调用类?
- hive - 如何决定我应该在我的项目中使用 Hive 还是 sparkSQL
- node.js - NodeJS:尝试导入模块时出现“意外的标识符”
- javascript - 使用 Ajax 刷新表数据在 django 中不起作用
- arrays - 从 Ajax Post 请求中查找对象数组及其属性
- node.js - 如何获取 IPP 端点
- javascript - 用Javascript折叠底栏