【发布时间】:2020-01-01 02:37:43
【问题描述】:
无法评论我改编此代码的初始线程 (Track download progress of S3 file using boto3 and callbacks),因此希望有人可以在这里帮助我。我能够使用此代码显示文件上传的进度条,现在我需要对从 AWS S3 下载的文件执行相同的操作。任何帮助将不胜感激!
我知道我需要从 S3 而不是从本地文件系统获取文件的大小。我确定我需要调整一些愚蠢的代码才能使其正常工作。希望有人可以提供一些启示。 :)
def upload_to_aws(local_file, bucket, s3_file):
s3 = boto3.client('s3', aws_access_key_id=s3ak,
aws_secret_access_key=s3sk)
statinfo = os.stat(local_file)
up_progress = progressbar.progressbar.ProgressBar(maxval=statinfo.st_size)
up_progress.start()
def upload_progress(chunk):
up_progress.update(up_progress.currval + chunk)
try:
s3.upload_file(local_file, bucket, s3_file, Callback=upload_progress)
up_progress.finish()
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
【问题讨论】:
-
您已经下载并需要上传?反之亦然?
-
我已经为上传工作了,现在只需要弄清楚如何进行下载:)
标签: python amazon-web-services amazon-s3 boto3 boto