up/download works
This commit is contained in:
parent
d9191b17af
commit
33f05f8b14
1 changed files with 6 additions and 12 deletions
18
app.py
18
app.py
|
@ -4,12 +4,12 @@ import uuid
|
|||
from flask import Flask, request, jsonify, send_from_directory
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['UPLOAD_FOLDER'] = os.environ.get('UPLOAD_FOLDER', '/uploads')
|
||||
app.config['UPLOAD_FOLDER'] = os.environ.get('UPLOAD_FOLDER', '/home/mg/api/python-api-server/uploads')
|
||||
app.config['MAX_CONTENT_LENGTH'] = int(os.environ.get('MAX_CONTENT_LENGTH', '5')) * 1024 * 1024 # in MB
|
||||
|
||||
VALID_FILENAME_REGEX = r'^[a-zA-Z0-9\-_\.]+$'
|
||||
|
||||
UPLOAD_TOKEN = os.environ.get('UPLOAD_TOKEN')
|
||||
UPLOAD_TOKEN = os.environ.get('UPLOAD_TOKEN', 'myuploadotken')
|
||||
|
||||
def is_valid_filename(filename):
|
||||
return bool(re.match(VALID_FILENAME_REGEX, filename))
|
||||
|
@ -34,7 +34,7 @@ def upload_file():
|
|||
|
||||
filename = file.filename
|
||||
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
return jsonify({'success': 'File {} successfully uploaded'.format(filename)})
|
||||
return jsonify({'success': 'File \'{}\' successfully uploaded'.format(filename)})
|
||||
|
||||
@app.route('/download/<filename>', methods=['GET'])
|
||||
def download_file(filename):
|
||||
|
@ -46,17 +46,11 @@ def download_file(filename):
|
|||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))
|
||||
|
||||
|
||||
|
||||
|
||||
# Upload
|
||||
# curl -X POST -H "token: myuploadtoken" -F "file=@/path/to/file" http://docker10.grote.lan:5040/upload
|
||||
# touch ../hallowelt && curl -X POST -H "token: myuploadtoken" -F "file=@../hallowelt" http://docker10.grote.lan:5040/upload
|
||||
# Download
|
||||
# curl -X GET http://docker10.grote.lan:5040/download/filename.ext > filename.ext
|
||||
# List
|
||||
# curl -X GET http://docker10.grote.lan:5040/files
|
||||
# Metriken
|
||||
# curl -X GET http://docker10.grote.lan:5040/metrics
|
||||
# wget http://docker10.grote.lan:5040/download/hallowelt
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Reference in a new issue