bottle.py如何批量上传图片?

How to batch upload images with bottle.py?

将大量图片上传到服务器并保存在服务器上的最佳方法是什么?

我尝试从如下形式获取文件:

<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>

控制器如下所示:

@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)

但显然它不起作用并且 "request.files.getall('gallery')" returns 无效。

我也用过 "bottle.request.forms.getall('gallery')" 但这个 returns 只用文件名,不用文件流。

对此有什么想法吗?

对于我个人的 bottle 项目,我在客户端使用了开源 plupload JS 库,并为 bottle 做了一个小包装。

你可以安装它:

pip install plupload

然后使用它:

@post('/upload')
def index():
    from plupload import plupload
    return plupload.save(request.forms, request.files, os.getcwd())

查看 https://github.com/JonathanHuot/bottlepy-plupload 了解更多示例。