12 lines
460 B
Python
12 lines
460 B
Python
from django.core.files.base import ContentFile
|
|
from django.db.models.functions import TruncDate
|
|
import base64
|
|
|
|
|
|
def base64_to_image_file(base64_string, filename="image.jpg"):
|
|
""" convert base64 to image, pdf,..... """
|
|
|
|
img_format, img_str = base64_string.split(';base64,') # split before & after of ';base64,'
|
|
ext = img_format.split('/')[-1] # split format of file
|
|
return ContentFile(base64.b64decode(img_str), name=f"{filename}.{ext}"), ext
|