如何从HttpResponseMessage中读取MultipartFormDataContent

时间:2015-01-09 08:57:54

标签: vb.net asp.net-mvc-4 asp.net-web-api

我正在创建一个Web API应用程序,它在HttpResponseMessage中向用户返回多个文件。以下是HttpResponseMessage对象

的示例
  Dim apple, banana As Byte()

  apple = File.ReadAllBytes("some place")

  banana = File.ReadAllBytes("some place")

  Dim multiDataContent As New MultipartFormDataContent()

  multiDataContent.Add(New ByteArrayContent(apple), "apple", "apple.xml")

  multiDataContent.Add(New ByteArrayContent(banana), "banana", "banana.xsd")


  Dim response As HttpResponseMessage = New HttpResponseMessage(HttpStatusCode.OK)

  response.Content = multiDataContent

  return response

我的问题是如何阅读MultipartFormDataContent,因为返回给客户的对象是StreamContent (response.Content),我该如何阅读MultipartFormDataContent

提前致谢

1 个答案:

答案 0 :(得分:0)

请参阅http://www.strathweb.com/2012/08/a-guide-to-asynchronous-file-uploads-in-asp-net-web-api-rtm/

重要的是,不要忘记将System.Net.Http.Formatting添加到项目中并将“Imports System.Net.Http.Formatting”添加到类中,以便您可以使用HttpContentMultipartExtensions。