-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle 413 Response when trying to upload a very large image #702
Comments
I was trying to fix that but I ran into another issue for upload, probably not related. |
Yeah not related. It's happening on the current master. |
That's an interesting error, @karlcow. Steps to reproduce? |
@miketaylr ok solved my issue. Do you want to open a bug and make a pull request for it. I can go back to this bug. :) |
Back to the bug. Testing. ok tested the 413 error handler.
We receive a 413 but I guess it's just for now the behavior of the Upload extension. |
Ah ok http://flask.pocoo.org/docs/0.10/patterns/fileuploads/#improving-uploads The request we send: POST / HTTP/1.1
Host: localhost:5000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Referer: http://localhost:5000/
Cookie: session=*****
Connection: keep-alive |
Any progress on this @karlcow? |
Let me check again:
So we do not have a handler for 413 in Flask but that would not matter anyway, because there is an issue before hand. Our super testing method. 🐒 @uploads.route('/', methods=['POST'])
def upload():
'''Endpoint to upload an image.
If the image asset passes validation, it's saved as:
UPLOADS_DEFAULT_DEST + /year/month/random-uuid.ext
Returns a JSON string that contains the filename and url.
'''
print "we are in uploads.route"
if 'image' in request.files and request.files['image'].filename:
print "first"
imagedata = request.files['image']
print "second"
elif 'screenshot' in request.form:
imagedata = request.form['screenshot']
else:
# We don't know what you're trying to do, but it ain't gonna work.
print "abort 501"
abort(501)
try:
print "we are in the try"
upload = Upload(imagedata)
print "after upload Class"
upload.save()
print "after upload save"
data = {
'filename': upload.get_filename(),
'url': upload.get_url()
}
return (json.dumps(data), 201, {'content-type': JSON_MIME})
except (TypeError, IOError):
abort(415)
except RequestEntityTooLarge:
print "do we reach 413?"
abort(413) Let's run with a small image.
All good! 🐵 Now let's try with a big image. We get a And the following log:
no print statements at all. 🙈 |
http://flask.pocoo.org/snippets/47/
|
Ah…
Logical. There is a piece of code to handle this, but it kind of creates a layer which is a bit weird. Maybe it's better to not address it? I wonder how Blink, Webkit and Edge browsers are handling this. |
Hmm. It would be nice to prevent a CONNECTION RESET page -- that makes it feel like the browser or site is busted, IMO (rather than reflect that the user is trying something a little crazy). What does the middleware look like? |
@miketaylr follow the link to the snippets the code is there. |
Ah, sorry, I only read the quoted text, didn't realize that was a link. 🙈 |
Karl told me to close this. |
This was fixed by #1049. |
We set the limit at 4MB, and if you try to upload something larger the error is currently swallowed. We should figure out how to send back a JSON error message and consume that in our regular form validation message stuff.
The text was updated successfully, but these errors were encountered: