I want to upload several files to the Bottle server.
Uploading a single file works well, and by changing the HTML input tag, which is "multiple," the browse button allows you to select multiple files. The download request handler downloads only the last file. How can I upload all files in one go?
The code I'm experimenting with:
from bottle import route, request, run
import os
@route('/fileselect')
def fileselect():
return '''
<form action="/upload" method="post" enctype="multipart/form-data">
Category: <input type="text" name="category" />
Select a file: <input type="file" name="upload" multiple />
<input type="submit" value="Start upload" />
</form>
'''
@route('/upload', method='POST')
def do_upload():
category = request.forms.get('category')
upload = request.files.get('upload')
print dir(upload)
name, ext = os.path.splitext(upload.filename)
if ext not in ('.png','.jpg','.jpeg'):
return 'File extension not allowed.'
save_path = "/home/user/bottlefiles"
upload.save(save_path)
return 'OK'
run(host='localhost', port=8080)
source
share