1,读取图片数据(二进制读取)
2,返回数据,并将mimetype设为图片格式对应的mimetype
示例代码
def get_image(uri):
imgPath = '../../static/uploads' + uri
mdict = {
'jpeg': 'image/jpeg',
'jpg': 'image/jpeg',
'png': 'image/png',
'gif': 'image/gif'
}
mime = mdict[((uri.split('/')[1]).split('.')[1])]
if not os.path.exists(imgPath):
# Res 是我自己定义的返回类,raw方法将数据组成字典返回
return jsonify(Res(0, 'image does not exists').raw())
with open(imgPath, 'rb') as f:
image = f.read()
return Response(image, mimetype=mime)