Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

browser - Upload file larger than MAX_CONTENT_LENGTH in Flask results connection reset

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...