I try to upload a file to S3 (in fact, the download works), but my application crashes and gives an error message:
fp is at EOF. Use rewind option or seek() to data start.
I saw that some ways to solve the problem were to add rewind=True to the set_contents_from_string call. However, this causes the following error:
set_contents_from_string() got an unexpected keyword argument 'rewind'
Below is the content of my views.py . What am I doing wrong?
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) ...
source share