我公开了一个content-type = multipart / form-data的flask api,它同时使用json和.zip文件作为输入。尝试阅读时,我可以获得zip文件。但是,我无法读取json文件。我尝试了几件事,但它们都没有json数据。甚至支持吗?
我正在使用flask restplus解析器使用“ werkzeug.datastructures import FileStorage”读取文件内容,而要获取json,我使用了下面给出的不同选项,但没有用 -> request.form
-> dict(request.form)
-> request.files.get_json(force = True)
-> api.payload
from werkzeug.datastructures import FileStorage, ImmutableMultiDict
parser= api.parser()
parser.add_argument('opc-retry-token', location='headers',required='true')
parser.add_argument('file', location='files', type=FileStorage, required=True)
def init(self):
args = parser.parse_args()
token = args['opc-retry-token']
self.token=token
self.args=args
logger.info(args)
# above log gives {'opc-retry-token': '1234', 'file': <FileStorage:
@ns.route('/prepare')
@api.expect(parser)
class OICPrepare(Resource):
@api.expect(oic_prepare)
def post(self):
init(self)
logger.info(request.form)
# above log gives 'None'
data = dict(request.form)
logger.info(data)
# above log gives ImmutableMultiDict([])
logger.info(request.files.get_json(force=True))
#above log gives {}
upload_file = self.args['file']
upload_file.save('/oic_admin/wallet.zip')
#above save command does the zip file properly
我希望zip文件和json都能被flask API读取。