如何将上传组件与 WebAPI 一起使用?

How do I use the Upload component with WebAPI?

我有一个 Web API 后端并尝试使用 Kendo 上传到 post 文件到服务器。 Telerik/Progress 的所有文档仅供客户端使用。 如何设置 Web api 操作以接受 Kendo 上传文件?

好的,这是经过一系列谷歌搜索和推论后我的解决方案:

[HttpPost]
public async Task UploadFile()
{
    if (Request.Content.IsMimeMultipartContent())
    {
        var msp = Request.Content.ReadAsMultipartAsync();
        foreach (var content in msp.Contents.Where(x => x.Headers.ContentDisposition.Name == "\"files\""))
        {
            byte[] file = await content.ReadAsByteArrayAsync();
            string fileName = content.Headers.ContentDisposition.FileName.Trim('"');
        }

        //  and if you set additional data via upload event like so:
        //  uploadEvent(e: UploadEvent): void {
        //      e.data = { yourDataKey: "abcdef" };
        //  }
        string yourData = await msp.Contents.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "\"yourDataKey\"").ReadAsStringAsync();
    }
}