python Flask request 获取多文件

python Flask request 获取文件
通常我们获取一个文件的话,就用request.files['file[]']获取文件对象,有些程序上传多文件直接会分多次请求,就还是用获取一个文件即可。
今天碰到的是有多个文件放在一次请求里的。


查了下资料就需要用到request.files.getlist('file[]')来获取一个迭代对象了

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
from flask import request
def uploadImg():
imgs = request.files.getlist('file[]')
print(imgs)
path = IMGPATH
for img in imgs:
print(img.filename)
filename = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + \
(img.filename[-8:]) # 图片防止重复
file_path = path + filename
img.save(file_path)
(完)
0条看法
最新最后最热
等待你的评论