小编Yot*_*Raz的帖子

在 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
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

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>
Run Code Online (Sandbox Code Playgroud)

url amazon-s3 amazon-web-services python-3.x boto3

5
推荐指数
1
解决办法
4207
查看次数

标签 统计

amazon-s3 ×1

amazon-web-services ×1

boto3 ×1

python-3.x ×1

url ×1