繁体   English   中英

使用python库s3fs写入AWS S3会因EntityTooLarge而失败

[英]Writing to AWS S3 using python library s3fs fails with EntityTooLarge

我知道AWS S3 API中存在一个限制,用于上传大于5 GB的文件。 boto3我应该使用multipart

我试图在S3File中配置S3File对象来做同样的s3fs ,但我无法弄明白。

我正在使用(作为错误的一个例子)一个非常基本的代码:

import s3fs

s3 = s3fs.S3FileSystem()

with s3.open("s3://bucket/huge_file.csv", "w") as s3_obj:
   with open("huge_file.csv") as local_file
       s3_obj.write(local_file.read())

其中huge_file.csv的大小> 5Gb

我得到的错误是

...
botocore.exceptions.ClientError: An error occurred (EntityTooLarge) when calling  the PutObject operation: Your proposed upload exceeds the maximum allowed size

...

File ... /s3fs/core.py" line 1487, in __exit__

self.close()

File ... /s3fs/core.py" line 1454, in close

所以,问题是如何(如果可能的话)我可以设置s3fs来上传大于5Gb文件(如何设置它来进行多部分上传)?

我认为这个Github线程可以解决你遇到的任何问题,并让你的生活更轻松我认为这就是你正在寻找的。

import boto3
from boto3.s3.transfer import TransferConfig

# Get the service client
s3 = boto3.client('s3')

GB = 1024 ** 3
# Ensure that multipart uploads only happen if the size of a transfer
# is larger than S3's size limit for nonmultipart uploads, which is 5 GB.
config = TransferConfig(multipart_threshold=5 * GB)

# Upload tmp.txt to bucket-name at key-name
s3.upload_file("tmp.txt", "bucket-name", "key-name", Config=config)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM