Skip to content Skip to sidebar Skip to footer

Attributeerror: 'bytes' Object Has No Attribute '_committed'

I have a form with an , and I'm getting an error when I try to save the uploaded image. The image is uploaded via POST XMLHttpRequest. I have no idea why t

Solution 1:

You're only uploading a single file; you shouldn't be iterating over the file key.

defupload_file(request):
    key = f'{request.user}-{datetime.datetime.now().strftime("%Y%m%d%H%M%S")}'
    file = request.FILES.get('file')
    if file:
        img = TemporaryImage(image=file, key=key)
        img.save()

Solution 2:

i guess you have too try to save your image this way:

from django.core.files.base import ContentFile
...
defupload_file(request):
    key = f'{request.user}-{datetime.datetime.now().strftime("%Y%m%d%H%M%S")}'
    file = request.FILES.get('file')
    if file :
        img = TemporaryImage.objects.create(key=key)
        img.image.save(key, ContentFile(file), save=True)

Post a Comment for "Attributeerror: 'bytes' Object Has No Attribute '_committed'"