flask 上传图片
code
from flask import Flask from flask_restful import Api, Resource, reqparse import werkzeug app = Flask(__name__) api = Api(app) class Uploads(Resource): def post(self): parser = reqparse.RequestParser() parser.add_argument('file', type=werkzeug.FileStorage,location='files', action='append') args = parser.parse_args() files = args.file for file in files: file.save('test.jpeg') return {'msg': '文件上传成功!'} api.add_resource(Uploads, '/upload') if __name__ == '__main__': app.run(debug=True)
上传图片: