错误:文件对象没有属性siz

2024-04-27 22:32:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用django-storages将文件存储到aws3中。上传过去工作正常的文件。但当我把django从1.10降到1.8时。我在item.item_profile.save(filename.name,photofile)行收到奇怪的错误。在

代码:

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({})

错误:

^{pr2}$

Tags: 文件djangonameidzoneobjectsrequestsave