I am using a file chooser to ask users for image files(png or jpeg). Whenever I upload photos taken from an iPhone the image appears incomplete. I am saving the uploaded images as bytes in a mysql database and then later converting them to base64 strings.
ph = request.files[form.picture.name]
pic = request.files[form.picture.name].read()
pic = Image.open(BytesIO(pic))
pic = pic.convert('RGB')
imgByteAr = BytesIO()
pic.save(imgByteAr, format='JPEG')
imgByteAr = imgByteAr.getvalue()
pic.close()
imgByteAr is then saved into my database. However, when I run base64.b64encode(imgByteAr).decode('utf-8') from the base64 module and display it in an img tag the image comes out like this. I know that iOS 11 uses HEIC formatted images but even when I change the settings to only use JPEG the same error occurs. The problem disappears when using JPEG images from sources other than my iPhone. What makes JPEG images from an iPhone different?