WebAPI上传一个还包含图像的json对象

时间:2019-07-08 22:04:41

标签: c# json asp.net-web-api

我有一个WEB API,应将以下JSON对象作为POST输入:

{
  "WorkerID": 161,
  "RequestID": 1234,
  "CloseDate": "2019-07-08 12:41:13",
  "Coordinates": "12.42685 48.64234",
  "Status": "CLosed",
  "ActionPerformed": "somenthing has been done",
  "Attachments": [
    {
      "Data": "base64-data...",
      "MimeType": "image/jpg",
      "Name": "Image-20190101"
    },
    {
      "Data": "base64-data...",
      "MimeType": "image/jpg",
      "Name": "image-20190102"
    },
  ],
  "SatisfactionID": 3,
  "Token": "8168c4ce7924420eb3b86db07ed4fbe3"
}

我的问题是,一旦POST到达,我就不知道如何管理 Attachments.Data 字段并根据哑剧类型转换为图像在API控制器中。特别是如何解析和阅读它们。

我在服务器端创建了以下两个类:

public class RequestToClose
{
    public int WorkerID { get; set; }
    public int RequestID { get; set; }
    public string CloseDate { get; set; }
    public string Coordinates { get; set; }
    public string Status { get; set; }
    public string ActionPerformed { get; set; }
    public IList<Attachment> Attachments { get; set; }
    public int SatisfactionID { get; set; }
    public string Token { get; set; }
}

public class Attachment
{
    public string Data { get; set; }
    public string MimeType { get; set; }
    public string Name { get; set; }
}

0 个答案:

没有答案