python
from bottle import route, request, run
@route('/upload', method='POST')
def do_upload():
upload = request.files.get('file')
name, ext = os.path.splitext(upload.filename)
if ext not in ('.txt', '.pdf', '.doc'):
return 'File extension not allowed.'
save_path = '/path/to/save/uploads/'
if not os.path.exists(save_path):
os.makedirs(save_path)
file_path = "{path}/{file}".format(path=save_path, file=upload.filename)
upload.save(file_path)
return 'File successfully uploaded.'
run(host='localhost', port=8080)
python
from bottle import route, static_file, run
@route('/download/<filename:path>')
def do_download(filename):
return static_file(filename, root='/path/to/files/', download=filename)
run(host='localhost', port=8080)