简体   繁体   中英

How to batch upload images with bottle.py?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM