错误:文件对象没有属性大小

时间:2017-03-10 11:06:59

标签: python django django-storage

我正在使用django-storages将文件存储到AWS S3中。上传用于正常工作的文件。但是当我从django 1.10降级到1.8时。我在第item.item_profile.save(filename.name,photofile)行遇到了奇怪的错误。

CODE:

def PhotoUpload(request):
   if request.method == "POST":

       filename = request.FILES['profileimage']
       item_id = request.POST['item_id']
       item_name = request.POST['item_name']
       zone_id = request.POST['zone_id']

       photofile = tempfile.TemporaryFile()
       for chunk in filename.chunks():
           photofile.write(chunk)
       print filename
       zone = Zone.objects.get(user=request.user, zone_id=zone_id)
       item = Item.objects.get(zone=zone, item_id=item_id)
       item.item_profile.save(filename.name,photofile)
       item.save()
       photofile.close()
       response_data = {}
       return JsonResponse(response_data)
   return JsonResponse({})

ERROR:

 AttributeError at /home/photoupload/
'file' object has no attribute 'size'
 Request Method: POST
 Request URL: http://localhost:8000/home/photoupload/
 Django Version: 1.8.17
 Python Executable: /usr/bin/python
 Python Version: 2.7.3

     Traceback:
     File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
     132.response = wrapped_callback(request, *callback_args, **callback_kwargs)
     File "/home/sandesh/knowmenow/pythonserver/home/views.py" in PhotoUpload
      174.item.item_profile.save(filename.name,photofile)
     File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/files.py" in save
     106.         self._size = content.size

0 个答案:

没有答案
相关问题