Django base64转图片

import base64
def uploadImg(req):
    img=request.POST['img']
    ines = img.split('base64,')
    imgData = base64.b64decode(ines[1])
    timestamp = str(int(time.time()))
    file_url = 'static/upload/%s.%s' % (timestamp, 'jpg')
    leniyimg = open(file_url, 'wb')
    leniyimg.write(imgData)
    leniyimg.close()
    return JsonResponse({'ret':0,'msg':'success','img':file_url })

 

你可能感兴趣的:(Django)