[Flask] Control the size of uploaded files

1. Flask's solution to control the size of uploaded files is global control: http://docs.jinkan.org/docs/flask/patterns/fileuploads.html

from flask import Flask, Request

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024

2. Flask also has a plug-in: https://pythonhosted.org/Flask-Uploads/#flaskext.uploads.patch_request_class

Global control

3. The above two methods are not suitable for me. I need customization because there are multiple upload entries, and the upload file size limit of each entry is inconsistent.

 

Implementation idea: Set up a global control to limit the maximum file size allowed globally, then use flask to save the uploaded file locally, and use python to determine the size of the saved local file

fsize = os.path.getsize(filePath)

, And then judge based on the file size

There are many ways to judge the size of the front-end: jquery is one, so I won’t go into details here.

Reprinted at: https://www.cnblogs.com/shengulong/p/9366667.html

Guess you like

Origin blog.csdn.net/u013066730/article/details/108367818