0

Getting this error:

Exception Type: AttributeError
Exception Value: 'InMemoryUploadedFile' object has no attribute 'save'

When trying to have a Django function as simple as:

def upload(request):
    file = request.FILES["picture"]
    file.save("hello.png")
    return HttpResponse("done uploading")

Note: I know there is a longer way to make this simple procedure but I need it for now to be as simple as this one

1 Answers1

0

You can read the uploaded file in chunks and write to your desired file, see the documentation for details

def upload(request):
    file = request.FILES['picture']
    with open('hello.png', 'wb+') as destination:
        for chunk in file.chunks():
            destination.write(chunk)
    return HttpResponse('done uploading')
Iain Shelvington
  • 31,030
  • 3
  • 31
  • 50