lundi 1 avril 2019

Base64 image not saving correctly

I have a base64 encoded image uploaded to a Python Flask web app after using the croppie js library to crop an uploaded image. The saved file shows in the Linux file system but when I try to view the image, I am being told by various pieces of software that the file is invalid. I am not sure what I am doing wrong.

image1b64 = request.form['image1']
if image1b64 != None:
    print(image1b64)
    filename = eventImgDir + '/' + 'Image1.jpg' 
    if not os.path.exists(eventImgDir):
        os.makedirs(eventImgDir)
    with open(filename, 'wb') as f:
        f.write(base64.b64decode(image1b64))

Was hoping for a copped version of the original file to be uploaded but instead its just an unusable corrupt image file.




Aucun commentaire:

Enregistrer un commentaire