I noticed a strange behavior of Flask server when uploading files to it.
If I upload a 1GB file, before the first line of code is called in my endpoint, the disk usage is already increased by 1GB (checking with df -h). When I access the actual file in flask.request.files['file'] (this call takes some time, but) the disk usage grows by another 1GB. Eventually, when I try to save the file permanently on the server with .save() on the FileStorage object returned, the disk usage raises by 1GB more - total of 3GB for a moment, before the first 2GB are released.
In other words:
@app.route("/upload", methods=["POST"])
def upload():
# ... uploading 1 GB file
# 1GB of the server disk is already used
f = flask.request.files["file"]
# disk usage is 2GB at this point
f.save("foo")
# usage reaches peak of 3GB here, and then immediately reduced to just 1GB
Is this the standard behavior? Can I somehow provide the final path where I want to save the file and only have this file created?