Upload 0 byte file to Amazon S3

泄露秘密 提交于 2019-12-11 20:08:37

问题


Is it possible to upload a 0 byte file to Amazon S3? My standard response would be to not allow it, but I have a site that would like to allow users to upload blank .txt files, which happen to be 0 bytes.

Amazon returns a Malformed XML response:

<Error>
<Code>MalformedXML</Code>
<Message>The XML you provided was not well-formed or did not validate against our published schema</Message>
<RequestId>234...</RequestId>
<HostId>2309fsdijflsd...w32r09s</HostId>
</Error>

I'm using boto==2.3.0 with Flask==0.8


回答1:


Yes, it's possible.

>>> import boto
>>> c = boto.connect_s3()
>>> b = c.lookup('mybucket')
>>> k = b.new_key('empty')
>>> k.set_contents_from_string('')
>>> for k in b:
       print k.name, k.size
...
empty 0
...
>>>

At least that works for me. The error you are getting suggests something else is going wrong.



来源:https://stackoverflow.com/questions/10988102/upload-0-byte-file-to-amazon-s3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!