restful批量上传文件,如何使用flask_restful上传多个文件?

I'm trying upload multiple files with flask_restful, but can't get the files name list in the arguments except the first file name, how can i get the files list with args?

here is my code,

from models import Server

import werkzeug

from werkzeug import secure_filename

from settings import upload_folder,allowed_extensions,currentWorkingPath,os,sys,reqparse,Resource

from settings import fields,marshal_with,abort

from settings import redirect, url_for

'''

#######################################################Uploads API

'''

uploads_fields = {

'uri': fields.Url('uploads', absolute=True)

}

parser = reqparse.RequestParser()

parser.add_argument('file', type=werkzeug.FileStorage, location='files',required=True)

class Uploads(Resource):

@marshal_with(uploads_fields)

def post(self):

args = parser.parse_args()

print 'file',args

......

what i got is:

* Restarting with stat

* Debugger is active!

* Debugger pin code: 115-504-357

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

file {'file':

)>}

127.0.0.1 - - [18/Jan/2017 10:40:38] "POST /uploads/ HTTP/1.1" 200 -

in fact I selected two files simple_api-master.zip,simple_api-master-old.rar and passed value throught post method, so the print function should output u'simple_api-master.zip',u'simple_api-master-old.rar', but now it only output the first file name, what should I do to get the files list?

解决方案

Basically, just add

action='append'

Your code should be now: parser.add_argument('file', type=werkzeug.FileStorage, location='files',required=True, action='append')

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值