Tweaks to file_server initialisation

We are setting a sensible default for the storage folder and loading
that automatically, this way we avoid having a compulsory config file.
This commit is contained in:
2015-04-24 11:57:40 +02:00
parent 74e875a338
commit 770838f0fc
4 changed files with 23 additions and 22 deletions

View File

@@ -14,8 +14,6 @@ from bson import ObjectId
from datetime import datetime
from datetime import timedelta
from file_server import file_server
RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
@@ -184,4 +182,7 @@ def post_item(entry, data):
app = Eve(validator=ValidateCustomFields, auth=CustomTokenAuth)
# The file_server module needs app to be defined
from file_server import file_server
app.register_blueprint(file_server, url_prefix='/file_server')

View File

@@ -3,7 +3,8 @@ import os
from flask import Blueprint
from flask import request
import config
from application import app
file_server = Blueprint('file_server', __name__,
template_folder='templates',
@@ -22,10 +23,10 @@ def index(file_name=None):
#POST file
file_name = request.form['name']
folder_name = file_name[:2]
file_folder_path = os.path.join(config.Development.FILE_STORAGE,
file_folder_path = os.path.join(app.config['FILE_STORAGE'],
folder_name)
if not os.path.exists(file_folder_path):
os.mkdir(file_folder_path)
os.mkdir(file_folder_path)
file_path = os.path.join(file_folder_path, file_name)
request.files['data'].save(file_path)