Allow Django Imagefield Accept Base 64 Image

[Solved] Allow Django Imagefield Accept Base 64 Image | Python Frameworks Django - Code Explorer | www.yomemimo.com
Question : allow django imagefield accept base 64 image

Answered by : elias-imokhai

pip install pillow
import base64
import io
from PIL import Image
from django.core.files.uploadedfile import InMemoryUploadedFile
def decodeDesignImage(data): try: data = base64.b64decode(data.encode('UTF-8')) buf = io.BytesIO(data) img = Image.open(buf) return img except: return None	img = decodeDesignImage(data) img_io = io.BytesIO() img.save(img_io, format='JPEG') design.image = InMemoryUploadedFile(img_io, field_name=None, name=token+".jpg", content_type='image/jpeg', size=img_io.tell, charset=None) design.save()

Source : https://idiomaticprogrammers.com/post/how-to-save-base64-encoded-image-to-django-imagefield/ | Last Update : Fri, 24 Jun 22

Answers related to allow django imagefield accept base 64 image

Code Explorer Popular Question For Python Frameworks Django