Re: [flask] file size and 413
- Slava Bacherikov
- 2013-10-30 @ 12:11
You are not obligated to do so. Also note if http server have limit for
maximum client body , it could reject this request before it goes to
If you want catch this exception, you should know that flask uses
request wrapper from werkzeug. This wrapper are lazy. This means that
client request would be parsed only if we need it.
I created an example to demonstrate this
Run upload.py and execute this.
$ dd bs=1024 count=5 if=/dev/urandom of=./testfile # this will
create 5 Kb file
$ curl -X POST -F file=@./testfile http://127.0.0.1:5000/ # and this
will send it to main page
Then you will see this in application log:
INFO in upload [upload.py:15]:
413: Request Entity Too Large
Also, try do this:
$ curl -X POST -F file=@./testfile http://127.0.0.1:5000/exception/
$ curl -X POST -F file=@./testfile http://127.0.0.1:5000/exception2/
$ curl -X POST -F file=@./testfile http://127.0.0.1:5000/exception3/
30.10.2013 10:55, Максим Карелов пишет:
> How i can catch this exception? "try"
> with request.files["file"] not working
> 30.10.13, 12:30, "Slava" <email@example.com>":
>> 413 status code means that file too large
>> This exception would be raised before file.save would be executed, it
raised when form begins parsing.
>> Also you may limit max upload file size on server, for example on nginx
>> 29 окт. 2013, в 23:53, Максим Карелов <firstname.lastname@example.org> написал(а):
>>> Hello. Help me, please. I've made image upload to my site, define
MAX_CONTENT_LENGTH in config and use "try" to upload file to folder. But
with big files (> than my config value) flask returns 413 error without
"except RequestEntityTooLarge" hook. What I'm doing wrong? Sorry my eng.
Slava Bacherikov <email@example.com>