Save temporary files in STORAGE_DIR

This makes it trivial to save uploaded files to STORAGE_DIR, as the
temporary files Flask saves them in are already there.
This commit is contained in:
2016-05-03 11:22:54 +02:00
parent 0580d3fa65
commit 0389b05b14
2 changed files with 32 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import logging
import os
import json
import tempfile
from bson import ObjectId
from datetime import datetime
import bugsnag
@@ -101,7 +101,14 @@ if from_envvar:
# configfile doesn't exist, it should error out (i.e. silent=False).
app.config.from_pyfile(from_envvar, silent=False)
# Set the TMP
# Set the TMP environment variable to manage where uploads are stored.
# These are all used by tempfile.mkstemp(), but we don't knwow in whic
# order. As such, we remove all used variables but the one we set.
tempfile.tempdir = app.config['STORAGE_DIR']
os.environ['TMP'] = app.config['STORAGE_DIR']
os.environ.pop('TEMP', None)
os.environ.pop('TMPDIR', None)
# Configure logging
logging.basicConfig(