如何在webapi2中读取文件数据



我使用MultipartFormDataStreamProvider读取上传的文件,如下面的片段所示。然而,这并不安全,因为它将文件直接保存到temp。首先,我想检查原始字节并执行一些验证检查。请告诉我如何访问原始字节。

if (Request.Content.IsMimeMultipartContent())
{
    MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider("C:temp");
     return this.Request.Content
            .ReadAsMultipartAsync<MultipartFormDataStreamProvider>(streamProvider)
            .ContinueWith((tsk) =>
            {
                 MultipartFormDataStreamProvider provider = tsk.Result;
            });

}

var provider = await Request.Content.ReadAsMultipartAsync(new MultipartMemoryStreamProvider());
foreach (var c in provider.Contents)
{
  var stream = await c.ReadAsStreamAsync();
  // do something with the stream
}

相关内容

  • 没有找到相关文章

最新更新