flask 返回图片
code
from flask import Flask,Response 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': '文件上传成功!'} class download(Resource): def get(self): with open("test.jpeg", 'rb') as f: image = f.read() return Response(image, mimetype='image/jpeg') api.add_resource(Uploads, '/upload') api.add_resource(download, '/download') if __name__ == '__main__': app.run(debug=True)
访问图片