Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload file larger than MAX_CONTENT_LENGTH in Flask results connection reset

Tags:

browser

flask

I'm trying to limit upload file size, I set app.config['MAX_CONTENT_LENGTH'] to the maximum value I want,

I used this code to display the error.

@app.errorhandler(413)
def request_entity_too_large(error):
    return 'File Too Large', 413

When using curl, the error displayed correctly. I checked using Firefox/Safari, in both I get browser error of connection dropped/reset.

Firefox

The connection was reset

The connection to the server was reset while the page was loading.

    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer's network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

Safari

Can't open the page
...server unexpectedly dropped the connection...

server log in all of those requests

192.168.1.1 - - [23/May/2015 15:50:34] "POST / HTTP/1.1" 413 -

Why the error doesn't display correctly?

like image 390
Neet33 Avatar asked Nov 09 '22 12:11

Neet33


1 Answers

It's an issue related to Flask's development server, you needn't worry about it. Run the application with production server will solve this problem.

In this snippet that posted by Armin Ronacher, he said:

You might notice that if you start not accessing .form or .files on incoming POST requests, some browsers will honor this with a connection reset message. This can happen if you start rejecting uploads that are larger than a given size.

Some WSGI servers solve that problem for you, others do not. For instance the builtin Flask webserver is pretty dumb and will not attempt to fix this problem.

See update here.

like image 123
Grey Li Avatar answered Dec 29 '22 15:12

Grey Li