Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

flask接收多个文件上传

各位大侠,我在用flask接收前端多个文件上传,然后存在云服务器上,代码如下:

@application.route('/shangchuan9/',methods=['GET','POST'])

def shangchuan9():

?? if request.method == 'POST':

???? basepath = os.path.dirname(__file__)

???? fs = request.files.getlist('files')?# 一次性多个文件

???? for f in fs:

?????? new_fname = os.path.join(basepath, '/home/ftpadmin/zhishiren/documents/',

f.filename)

?????? f.save(new_fname)

???? response = {'msg':1}

???? return jsonify(response)

前端反馈的结果是200ok,能返回msg的值,但我却没有发现文件被保存在制定的服务器路径下,各位帮我看看


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

靠,是我搞错了, fs = request.files.getlist('files'),我之前用的是getlist[] !!低级错误


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...