I'm writing an API for mobile clients and an AngularJS web front end using ASP.NET 5. Everything's going well, but I'm stumped on how to create a POST to upload files to the server.
The best info I've found is in this thread. Based on the research I've done, I want to do something like the following, but I keep getting shot down by VS2015 and it's inability to find proper references.
[HttpPost("card/{cardId}/image")]
public async Task<IActionResult> Upload()
{
var provider = new MultipartMemoryStreamProvider();
await Request.Body.ReadAsMultipartAsync(provider);
foreach (var file in provider.Contents)
{
var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
var buffer = await file.ReadAsByteArrayAsync();
//Do whatever you want with filename and its binaray data.
}
return Json (new { Message = "Hooray!" });
}
...and here's what VS2015 makes of it:
With DNXcore5.0 it seems that MultipartMemoryStreamProvider which is part of System.Net.Http can't be found in the namespace, and Request.Body doesn't work with ReadAsMultipartAsync (which couldn't be found anyway, because it's in that System.Net.Http space...)
Is there a better way to set up an API POST to accept files in ASP.NET 5? Or how do we now reference things like System.Net.Http that have worked for years?