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 = get_save_path_for_category(category)
save_path = "/home/user/bottlefiles"
upload.save(save_path) # appends upload.filename automatically
return 'OK'
run(host='localhost', port=80)
Computer has revolutionized the world and programming is the most important tool to make our dream come true;
Friday, April 1, 2016
bottle image upload
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment