我正在尝试将文件上传到 S3(实际上上传工作),但我的应用程序崩溃并抛出错误说:
fp is at EOF. Use rewind option or seek() to data start.
我看到人们解决问题的一些方法是添加rewind=True
到他们的 set_contents_from_string 调用中。但是,这会引发以下错误:
set_contents_from_string() got an unexpected keyword argument 'rewind'
以下是我的内容views.py
。我究竟做错了什么?
def store_in_s3(filename, filecontent):
conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
b = conn.create_bucket('mybucket')
mime = mimetypes.guess_type(filename)[0]
k = Key(b)
k.key = filename
k.set_metadata("Content-Type", mime)
k.set_contents_from_string(filecontent)
#k.set_contents_from_string(filecontent, rewind=True)
k.set_acl("public-read")
def add_m(request, points=None):
mname = request.GET.get ('mname')
format = request.GET.get ('format')
type = request.GET.get ('type')
if request.method == "POST":
formtoaddm = spiceform(request.POST, request.FILES)
if formtoaddm.is_valid():
new_m = formtoaddm.save(commit=False)
new_m.adder = request.user
mname = new_m.mname
file = request.FILES['content']
filename = file.name
filecontent = file.read()
store_in_s3(filename, filecontent)
...