Python 3.x 上传的文件在S3中不显示
我正在使用boto3,使用TransferConfig的多部分上传: 当程序运行时没有错误,一切似乎都正常:Python 3.x 上传的文件在S3中不显示,python-3.x,amazon-s3,boto3,Python 3.x,Amazon S3,Boto3,我正在使用boto3,使用TransferConfig的多部分上传: 当程序运行时没有错误,一切似乎都正常: import threading,boto3,re,os,sys from boto3.s3.transfer import TransferConfig #create resource s3=boto3.resource('s3', region_name = region, aws_access_key_id=ACCESS_
import threading,boto3,re,os,sys
from boto3.s3.transfer import TransferConfig
#create resource
s3=boto3.resource('s3',
region_name = region,
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
aws_session_token=SESSION_TOKEN)
BUCKET_NAME="my_bucket"
# the upload function
def multi_part_upload_with_s3():
# Multipart upload
config = TransferConfig(multipart_threshold=1024*25, max_concurrency=10000,
multipart_chunksize=1024*25, use_threads=True)
#file_path = os.path.dirname(__file__)+'/largefile.pdf'
file_path = "C:/Users/Documents/MyFile.out"
key_path = 'MyDir/MySubDir/'
s3.meta.client.upload_file(file_path, BUCKET_NAME, key_path,
#ExtraArgs={'ACL': 'public-read', 'ContentType':
'text/pdf'},
Config=config, Callback=ProgressPercentage(file_path))
#Not really important, just tells you what percentage of your file has uploaded.
class ProgressPercentage(object):
def __init__(self, filename):
self._filename = filename
self._size = float(os.path.getsize(filename))
self._seen_so_far = 0
self._lock = threading.Lock()
def __call__(self, bytes_amount):
with self._lock:
self._seen_so_far += bytes_amount
percentage = (self._seen_so_far/self._size)*100
sys.stdout.write("\r%s %s/%s (%.2f%%)" % (self._filename,
self._seen_so_far, self._size, percentage))
sys.stdout.flush()
#Now call fucntion
if __name__=='__main__':
multi_part_upload_with_s3()
输出:
C:/Users/Documents/MyFile.out 1295607/1295607.0 (100.00%)
因此,它似乎运行没有错误。然而,当我查看S3时,会创建“MySubDir”,但“MyFile.out”不在其中。我认为S3中的最大并发性可能是导致我认为需要一段时间才能重新加入它的罪魁祸首,但我已经等了4个多小时,什么也没有出现。我还使用了其他文件和其他上传方法,文件将显示在“MySubDir”中。您从不指定目标文件名,只指定路径。尝试:
file_path = "C:/Users/Documents/MyFile.out"
key_path = 'MyDir/MySubDir/MyFile.out'
s3.meta.client.upload_file(file_path, BUCKET_NAME, key_path,
#ExtraArgs={'ACL': 'public-read', 'ContentType':
'text/pdf'},
Config=config,Callback=ProgressPercentage(file_path))
您从不指定目标文件名,只指定路径。尝试:
file_path = "C:/Users/Documents/MyFile.out"
key_path = 'MyDir/MySubDir/MyFile.out'
s3.meta.client.upload_file(file_path, BUCKET_NAME, key_path,
#ExtraArgs={'ACL': 'public-read', 'ContentType':
'text/pdf'},
Config=config,Callback=ProgressPercentage(file_path))
天哪,真是个疏忽。一整天都过去了,但上传4TB文件可以节省几天,可能一周。非常感谢。天哪,真是个疏忽。一整天都过去了,但上传4TB文件可以节省几天,可能一周。非常感谢。