我尝试将文件上传到boto
,
import io
from boto.s3 import connection
from boto.s3 import key
conn = connection.S3Connection()
bucket = conn.get_bucket('my-bucket')
my_key = key.Key(bucket, 'asdf')
d = b'this is a test....\n' * 512000
f = io.BytesIO(d)
my_key.send_file(f, size=4*1024)
然而,这导致:
boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?><Error><Code>BadRequest</Code><Message>An error occurred when parsing the HTTP request.</Message><RequestId>[hex request ID]</RequestId><HostId>[giant piece of base64]</HostId></Error>
为什么此请求失败?
(注意:我在这里使用send_file
的全部原因是因为open
显然只支持阅读......)
答案 0 :(得分:7)
对于它的价值,将send_file()
替换为set_contents_from_file()
为我工作(我有同样的错误)。