我无法将文件上传到我刚在S3中创建的存储桶。
但是,另一个文件,我上传到不同的桶正常运行没有错误。 所以,我相信,问题在于存储桶本身而不是代码。
这是我的角色:
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
这是mycode的快照
class Handler:
...
def s3save(self, local_path, remote_path, metadata=None, savebucket=None):
chunk_size = Handler.CHUNK_SIZE
headers = self.default_s3_headers if metadata is None else metadata
mpu = savebucket.initiate_multipart_upload(
remote_path,
headers=headers,
policy="public-read"
)
# code copy-ed from someone from stackoverflow
source_size = os.stat(local_path).st_size
chunk_count = int(math.ceil(source_size / float(chunk_size)))
print(local_path, remote_path, savebucket)
for i in xrange(chunk_count):
offset = chunk_size * i
bytelength = min(chunk_size, source_size - offset)
with FileChunkIO(local_path, "r", offset=offset, bytes=bytelength) as fp:
mpu.upload_part_from_file(fp, part_num=i + 1)
mpu.complete_upload()
但无论如何,我仍然遇到这个错误:
error: [Errno 104] Connection reset by peer