I'm making an app that uploads images and sounds. That had been working very well for a long time. But now suddenly pictures can't be rendered in the html any more after having been uploaded.In cloud 9 I get" "invalid or unsupported file format". When I try to preview the image I get : The image 'https://preview.cs50.io/oyz1/ide50/pset9/wordPalace/static/images/2.png?_c9_id=livepreview3&_c9_host=https://ide.cs50.io'cannot be rendered because it contains errors. I have no problem opening it in my pc though. I've tried different file formats, different folders in my pc, I made it small, I tried everything I can think of and it won't work. I've followed flasks instructions on how to upload images and everything has been going super for months. I added some stuff on the front end but I've taken all that out so that I am left with the two bare bone functions but it just won't work. In the terminal I see this when I print request.files:


ImmutableMultiDict([('image', <FileStorage: '' ('application/octet-   


Here's the relevant code which I found and copied here: http://flask.pocoo.org/docs/1.0/patterns/fileuploads/


 UPLOAD_IMAGES_FOLDER = '../../pset9/wordPalace/static/images'
 ALLOWED_IMAGE_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])

args for tomato.png: 
{'table': 'images', 'column': 'image', 
 'file': ['meisje.png'], 
 'jointable': 'words_images', 'join_id': 'images_id', 
 'extensions': 'jpg, jpeg, png, gif'}

# when uploading a file check if it has an extension that is allowed
def allowed_file(args):

return '.' in args['file'][0] and \
       args['file'][0].rsplit('.', 1)[1].lower() in args['extensions']

 def uploadFile(args):

     if allowed_file(args):
         filename = secure_filename(args['file'][0])
         filepath = os.path.join(app.config[args['folder']], filename)
         return filename
        flash("You can ony save filenames with these extensions: " +   
        return "nok"


1 Answer 1


Ok, I got it. I posted a json object first, got a response back used that for form validation and then submitted the form, but of course, image data wasn't in the form any more because I had fully rendered the page again. The name of the image file was put back in but the original data for request.files was gone.

So sorry for all the fuss. I've done this before. My brain gets fried, I post a question in despair and then I feel a kind of release. My brain starts working again and I find the answer. This forum really works for me but not in the way intended. Really so sorry,

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .