Reputation: 98
What is the best way to upload a lot of images to server and save them on the server?
I have tried to get files from form that looks like this:
<form action="/upload" method="post">
<div class="form-group">
<label for="gallery">Select images:</label>
<input id="gallery" type="file" name="gallery" accept=".gif,.jpg,.jpeg,.png" multiple>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
And the controller looks as follows:
@route('/upload', method='POST')
def newGallery():
pictures = request.files.getall('gallery')
for picture in pictures:
picture.save("path/to/directory",overwrite=True)
return template('new.html', info)
But apparently it did not work and "request.files.getall('gallery')" returns null.
I did also use the "bottle.request.forms.getall('gallery')" but this one returns only the file names, not the file streams.
Any thoughts on that?
Upvotes: 2
Views: 368
Reputation: 2668
for my personal bottle project, I used open source plupload
JS library on client-side and did a small wrapper for bottle.
You could install it :
pip install plupload
And then use it :
@post('/upload')
def index():
from plupload import plupload
return plupload.save(request.forms, request.files, os.getcwd())
Have a look at https://github.com/JonathanHuot/bottlepy-plupload for more example.
Upvotes: 2