问题描述
我正在使用boto3制作备份脚本,并使用以下行来上传项目:
I'm making a backup script using boto3 using this line to upload the item:
bucket.upload_file(backup_file_name,bucket_path+backup_file_name)
如何验证此文件是否确实已上传到我的存储桶?我尝试使用boto3 doc查找内容,但未找到任何内容.这种方法会引发我可以处理的任何异常吗?
How can I verify if this file has really been uploaded to my bucket? I tried to find something using boto3 doc but I didn't found anything. Does this method throws any exception that I can handle?
推荐答案
它将提高boto3.exceptions.S3UploadFailedError
.您还可以执行 head_object
请求以验证对象看起来像它应该的样子.如果对象不存在,则会使用代码404
引发botocore.ClientError
.
It will raise boto3.exceptions.S3UploadFailedError
. You can also do a head_object
request to verify that the object looks like it should. This will raise a botocore.ClientError
with the code 404
if the object does not exist.
这篇关于Boto3:验证是否已使用upload_file()上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!