Flask: Get the size of request.files object

后端 未结 5 1335
旧巷少年郎
旧巷少年郎 2020-12-03 01:15

I want to get the size of uploading image to control if it is greater than max file upload limit. I tried this one:

@app.route(\"/new/photo\",methods=[\"POST         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 01:53

    As someone else already suggested, you should use the

    app.config['MAX_CONTENT_LENGTH'] 
    

    to restrict file sizes. But Since you specifically want to find out the image size, you can do:

    import os
    photo_size = os.stat(request.files['post-photo']).st_size
    print photo_size
    

提交回复
热议问题