librelist archives

« back to archive

file size and 413

file size and 413

From:
Максим Карелов
Date:
2013-10-29 @ 21:53
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.

Re: [flask] file size and 413

From:
Slava
Date:
2013-10-30 @ 08:28
413 status code means that file too large 
http://werkzeug.pocoo.org/docs/exceptions/#werkzeug.exceptions.RequestEntityTooLarge.
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 
http://wiki.nginx.org/HttpCoreModule#client_max_body_size .

29 окт. 2013, в 23:53, Максим Карелов <maks-karelov@ya.ru> написал(а):

> 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.

Re: [flask] file size and 413

From:
Максим Карелов
Date:
2013-10-30 @ 08:55
How i can catch this exception? "try"
 with request.files["file"] not working

30.10.13, 12:30, "Slava" <bacher09@yandex.ru>":
> 
> 413 status code means that file too large 
http://werkzeug.pocoo.org/docs/exceptions/#werkzeug.exceptions.RequestEntityTooLarge.
> 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 
http://wiki.nginx.org/HttpCoreModule#client_max_body_size .
> 
> 29 окт. 2013, в 23:53, Максим Карелов <maks-karelov@ya.ru> написал(а):
> 
> > 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.
> 

Re: [flask] file size and 413

From:
Slava Bacherikov
Date:
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
flask application.

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
https://gist.github.com/bacher09/7231395 .
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" <bacher09@yandex.ru>":
>> 413 status code means that file too large 
http://werkzeug.pocoo.org/docs/exceptions/#werkzeug.exceptions.RequestEntityTooLarge.
>> 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
http://wiki.nginx.org/HttpCoreModule#client_max_body_size .
>>
>> 29 окт. 2013, в 23:53, Максим Карелов <maks-karelov@ya.ru> написал(а):
>>
>>> 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 <slava@bacher09.org>