如何从POST请求中将jpeg提取到文件中? POST请求标头不是MimeMultipartContent
:(网络上的所有示例都显示。this.Request.Content.Headers.Contenttype.MediaType
包含字符串image/jpeg
和
Debug.Trace(this.Request.Content)
只是给了我"System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent"
到目前为止,这是我的代码:
public IHttpActionResult Post()
{
HttpRequestMessage request = this.Request;
Trace.WriteLine(request.Content.Headers.ContentType.MediaType); // "image/jpeg"
// Do the extraction to a file here
return Ok("Worked");
}
答案 0 :(得分:1)
从请求中提取内容流。从那里你可以用流做你想做的事。
public async Task<IHttpActionResult> Post() {
var request = this.Request;
Trace.WriteLine(request.Content.Headers.ContentType.MediaType); // "image/jpeg"
var imageStream = await request.Content.ReadAsStreamAsync();
//...save stream to disk or database...etc.
return Ok("Worked");
}