Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

allow django imagefield accept base 64 image

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()
Comment

PREVIOUS NEXT
Code Example
Python :: read sharepoint list using python 
Python :: negate all elements of a list 
Python :: Tree : Top View 
Python :: subsetting a column and giving it a value using numpy 
Python :: update value in xml python 
Python :: how to make a value 0 if its negatice 
Python :: use decorator more than once 
Python :: loc condition on first 3 columns of dataframe 
Python :: python multi arguments 
Python :: how to read file from terminal in python inside code 
Python :: empty show non python 
Python :: hoow to print python 
Python :: pandas set index integer not float 
Python :: qubesos 
Python :: reate the "soup." This is a beautiful soup object: 
Python :: first_list = [10,20,30,40] second list = first list second list[3]=400 
Python :: how to stop gambling 
Python :: if condition in djangio template 
Python :: install eric6 python ide ubuntu 20.04 
Python :: reportlab drawimage issues with png transparency background 
Python :: explorer gives new window 
Python :: file.write must be string python 
Python :: Return an RDD created by coalescing all elements within each partition into a list. 
Python :: arrotondamento python 
Python :: how to sort a list randomly in python 
Python :: how to acces textedit fields pyqt 
Python :: python qt grid span 
Python :: how to use drop for file in python 
Python :: python to exe converter online 
Python :: c++ code to python code converter online 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =