6
我試圖將文件上傳到boto
,爲什麼在上傳boto文件時會得到400?
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
顯然只支持讀取...)
如果您執行''my_key.set_contents_from_file(f)'',會發生什麼情況。你有同樣的錯誤嗎? – garnaat 2014-11-07 16:54:13
@garnaat調用成功;這一點的一部分是確保'boto'不會將整個文件讀入內存:如果添加size參數,'set_contents_from_file'只會讀取第一個'size'字節。 (這是文檔所說的功能,但不是我想要的。) – Thanatos 2014-11-07 21:26:51
這聽起來像你真正想要的是真正的流式傳輸,但不幸S3不支持這一點。至少還沒有。 – garnaat 2014-11-07 21:42:28