Python 值使用boto3从S3存储桶下载文件时出错?
我使用以下方法成功地从S3存储桶将图像文件下载到本地计算机:Python 值使用boto3从S3存储桶下载文件时出错?,python,python-3.x,amazon-web-services,amazon-s3,boto3,Python,Python 3.x,Amazon Web Services,Amazon S3,Boto3,我使用以下方法成功地从S3存储桶将图像文件下载到本地计算机: import os import boto3 import botocore files = ['images/dog_picture.png'] bucket = 'animals' s3 = boto3.resource('s3') for file in files: s3.Bucket(bucket).download_file(file, os.path.basename(file)) 但是,当我尝试在本地计算机
import os
import boto3
import botocore
files = ['images/dog_picture.png']
bucket = 'animals'
s3 = boto3.resource('s3')
for file in files:
s3.Bucket(bucket).download_file(file, os.path.basename(file))
但是,当我尝试在本地计算机上指定图像应保存到的目录时:
我得到:
ValueError: Invalid extra_args key '/home/user/storage/new_image.png', must be one of: VersionId, SSECustomerAlgorithm, SSECustomerKey, SSECustomerKeyMD5, RequestPayer
我一定是做错了什么,但我是在遵循文档中的示例。有人能帮我指定一个本地目录吗?查看文档,您提供了一个额外的参数
import boto3
s3 = boto3.resource('s3')
s3.Bucket('mybucket').download_file('hello.txt', '/tmp/hello.txt')
从文档中,hello.txt是bucket上对象的名称,/tmp/hello.txt是设备上的路径,因此正确的方法是
s3.Bucket(bucket).download_file(file, '/home/user/storage/new_image.png')
s3.Bucket(bucket).download_file(file, '/home/user/storage/new_image.png')