From the client's POST submission, we are successfully receiving an image in the following format, data:image/jpeg;base64,/9j/.... and an image file is being generated by the following code:
@app.route('/submission', methods=('GET', 'POST'))
def submission():
if request.method == 'POST':
raw_image = request.form['file']
#Problem Starts Here
# this doesn't work either:
# raw_image = raw_image.replace("data:image/jpeg;base64,/9j/", '');
with open(UPLOADED_IMAGES_DEST+'/image.jpeg', 'wb') as fh:
fh.write(base64.decodebytes(raw_image))
#Problem Ends Here
return jsonify(request.form)
return render_template('submission.html')
However, the image cannot be opened as it's an "Invalid or Unsupported Format". I'm trying to improve the conversion process so it will produce a viewable JPEG image.
Beginning of raw_image:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCADwAUADASIAAhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAABQYEBwIDCAEACf/EAEwQAAEDAwMCBAQEAwUFBQQLAAECAxEABAUGEiExQQcTUWEIInGBFDKRoRVCUiOxwdHwJGJyouEJFjOSwhdDgvEmU2ODk7LDxNLU4v/EABsBAAMBAQEBAQAAAAAAAAAAA...

raw_imageandimage.jpegfile ?raw_imagebut upon closer inspection, it looks like the file being created is empty and is 0 bytes.base64,todecodebytes()./9j....onwards todecodebytes(), but don't search for/9jbecause it will be different if you get a PNG file, for example.