【发布时间】:2022-08-24 17:40:03
【问题描述】:
以下是从 S3 存储桶下载文件的功能。 但问题是我找不到如何将这些文件定向到网络路径而不是下载到项目文件夹中,而无法控制必须下载文件的位置。
import boto3
import config
import os
import win32api
def download_all_objects_in_folder():
#= boto3.resource(\'s3\')
s3_resource = boto3.resource(\'s3\', aws_access_key_id=config.AWS_BUCKET_KEY, aws_secret_access_key=config.AWS_BUCKET_SECRET_KEY)
my_bucket = s3_resource.Bucket(config.BUCKET)
# Create the folder logic here
objects = my_bucket.objects.filter(Prefix=\'Export_20181104/\')
for obj in objects:
path, filename = os.path.split(obj.key)
my_bucket.download_file(obj.key, filename,\"C:\\Other\")
#win32api.MessageBox(0, obj.key, \'title\')
print(\"imports completed\")
更新: 这是我通过自定义路径时遇到的错误。
ValueError: Invalid extra_args key \'C\', must be one of: ChecksumMode,
VersionId, SSECustomerAlgorithm, SSECustomerKey, SSECustomerKeyMD5,
RequestPayer, ExpectedBucketOwner
-
共享文件夹的路径应该和本地路径一样添加。如果您的用户有权访问该路径,Windows 将识别该路径。
-
@GabrielDantas 感谢您的回复,我想知道在上面的代码中传递位置的选项在哪里? (本地或共享)。如果您以前尝试过,请告诉我。
标签: python amazon-web-services amazon-s3 boto3