You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

23 lines
715 B

import base64
from django.conf import settings
from django.core.files.base import ContentFile
def decode_base64(my_str, upload_to=None):
if "data:" in my_str:
my_str = my_str[my_str.index("base64,")+7:]
if not upload_to:
ext = my_str.split('/')[-1]
return ContentFile(base64.b64decode(my_str), name='temp.' + ext)
path = "%s/%s" % (settings.MEDIA_ROOT, upload_to)
url = "%s%s" % (settings.MEDIA_URL, upload_to)
with open(path, "wb") as fh:
fh.write(base64.b64decode(my_str))
return url
return my_str
def get_real_name(array, elem):
for i, j in array:
if i and (i == elem or j == elem):
return i