Loading Base64 String into Python Image Library

后端 未结 4 1596
旧时难觅i
旧时难觅i 2020-12-08 23:26

I\'m sending images as base64 string through ajax to django. In my django view I need to resize the image and save it in the file system.

Here is a base64 string(si

4条回答
  •  独厮守ぢ
    2020-12-09 00:12

    The beginning of the POSTed string (data:image/jpeg;base64,) is a header and should be removed before the decoding. The image is corrupted otherwise.

    photo = request.POST['photo'].partition('base64,')[2]
    image_data = b64decode(photo)
    someobject.photo.save('user.jpg', ContentFile(image_data), save=True)
    

提交回复
热议问题