我有一个Web API后端,并尝试使用Kendo Upload将文件发布到服务器。 Telerik / Progress的所有文档仅供客户端使用。 如何设置web api操作以接受Kendo上传文件?
答案 0 :(得分:0)
好的,这是我的一些谷歌搜索和演绎后的解决方案:
[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();
}
}