add delete endpoint
This commit is contained in:
parent
f9dda355fb
commit
a69875aa32
1 changed files with 16 additions and 0 deletions
16
app.py
16
app.py
|
@ -43,9 +43,25 @@ def download_file(filename):
|
|||
except FileNotFoundError:
|
||||
return jsonify({'error': 'File not found'}), 404
|
||||
|
||||
@app.route('/delete/<filename>', methods=['DELETE'])
|
||||
def delete_file(filename):
|
||||
if 'token' not in request.headers:
|
||||
return jsonify({'error': 'No token supplied'}), 401
|
||||
|
||||
if request.headers['token'] != AUTH_TOKEN:
|
||||
return jsonify({'error': 'Invalid token supplied'}), 401
|
||||
|
||||
path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||
try:
|
||||
os.remove(path)
|
||||
return jsonify({'success': 'File \'{}\' successfully deleted'.format(filename)})
|
||||
except FileNotFoundError:
|
||||
return jsonify({'error': 'File not found'}), 404
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))
|
||||
|
||||
|
||||
# Upload
|
||||
# touch ../hallowelt && curl -X POST -H "token: myuploadtoken" -F "file=@../hallowelt" http://docker10.grote.lan:5040/upload
|
||||
# Download
|
||||
|
|
Reference in a new issue