2017-10-19 120 views
0

我遇到了使用瓶子批量图像上传的问题。 request.files.getall()返回空列表,即使我选择并上传文件。Bottle request.files.getall()返回空列表

我的形式看起来如下:

<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(): 
    name = request.forms.get('name') 
    pictures = request.files.getall('gallery') 

    for picture in pictures: 
     print(picture.filename) 

    return template('new.html') 

感谢您的帮助。

+1

显示你的'new.html' –

+0

那就是:HTTPS:/ /pastebin.com/3pw86VK1 – Sudet

回答

1

forms.getall(*)工作

* .py文件

@bottle.get('/go') 
def go(): 
    return bottle.template('new.html') 

@bottle.post('/go') 
def goo(): 
    name = bottle.request.forms.get('email') 
    pictures = bottle.request.forms.getall('gallery') 
    for picture in pictures: 
     print(picture) 
    return bottle.template(' hi {{name}}, {{picture}} ', name=name, picture=picture) 

而且,改变form标签在new.html

<form method="post"> 
+0

它的工作原理。谢谢。任何想法为什么request.files('*')不起作用? – Sudet

+0

实际上现在的问题是我得到的文件名称,但我没有我想上传到服务器的文件。那么现在如何保存文件呢? 我会说“picture.save(path,overwrite = True)”不起作用,因为图片在这个解决方案中只是字符串。 感谢您的帮助。 – Sudet