应用场景:用postman、apifox测试时请求python接口,python接口接收上送过来文件对象
下面截图是apifox上送的文件对象
python接口中,接收此文件对象
# -*- coding:utf-8 -*- from flask import Flask, request, json import os from Config.constant import save_base_path, date_format, min_random, max_random, count_random, file_split1, file_split2 def get_file_content(file_path): """ 读取图片 """ with open(file_path, 'rb') as fp: return fp.read() @app.route('/test', methods=['POST']) def test(): request_sn = request.form['request_sn'] attr = request.form['attr'] img_path_file = request.files.get('image') # FileStorage # 图片保存至指定路径 i_path = save_base_path + '/' + img_path_file.filename print(i_path) img_path_file.save(i_path) # 读取图片bytes image = get_file_content(i_path) print(type(image)) print(image)
打印
/home/dev/datafiles/test/mao.jpeg
b’xb5x10iqix10xddxdex82X6xc7xb5Qxaaxccxeaxb7x90x7fxdd$xeax9dxb0x9fx95Lxdczxa4-xcexdcPfnxcdxa4x92xcfx97’
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)