简体   繁体   English

Webapi Multipart formdata接受图像和JSON数据

[英]Webapi Multipart formdata to accept Images and JSON data

I tried to implement Webapi Action method which need to take Multipart formdata (Images and JSON Complex data). 我尝试实现Webapi Action方法,该方法需要采用Multipart表单数据(图像和JSON Complex数据)。 But the Json data which I am sending is coming as part of Formdata key value pairs instead of JSON and i couldn't parse it as a object. 但是我要发送的Json数据是作为Formdata键值对的一部分而不是JSON传入的,我无法将其解析为对象。

I tried Advanced Rest client to test my API and below is sample request. 我尝试了Advanced Rest客户端来测试我的API,以下是示例请求。

在ARC中索取样品

Is there a way, to make the API Controller to accept both files and Complex JSON object in a single action method. 有没有一种方法可以使API控制器在单个操作方法中既接受文件又接受复杂的JSON对象。

Yes, You can. 是的你可以。 For that you have to convert file into Base 64 String. 为此,您必须将文件转换为Base 64 String。 And than after add that string object to your model. 然后将字符串对象添加到模型中。 so that you can get your data and file in base 64 format to your controller. 这样您就可以将base 64格式的数据和文件发送到控制器。 and for that you don't need multipart/form-data. 因此,您不需要multipart / form-data。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM