I want to be able to check for the size of uploaded files. And if it exceeds a limit, i want to be able to issue my REST API errors.
I have this code:
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024
If you try to upload a file that is larger than 1MB, the application will now refuse it.
But this does not give me a lot of control, in terms of the REST API message that my app will generate.
So how can i check for max size of uploaded file, and issue my personal message, along with an HTTP status code, whenever that happens?
EDIT: Now i receive this on my curl terminal (client side)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>413 Request Entity Too Large</title>
<h1>Request Entity Too Large</h1>
<p>The data value transmitted exceeds the capacity limit.</p>
While i would like to send something like this (server side code):
return make_response(json.dumps({'error_message': 'file size too large'}), 413)