I achieved this by posting the file to blob storage and taking the associated metadata from a formcollection on the same page. In my POST I use IO steam to read the file and the associated metadata as shown below:
[HttpPost]
public ActionResult NewContent(HttpPostedFileBase postedFile,FormCollection form)
{
if (postedFile != null)
{
HttpPostedFileBase postedFileCopy = postedFile;
postedFileCopy.InputStream.Position = 0;
Stream stream = postedFile.InputStream;
string[] name = form.GetValues("name");
string[] author = form.GetValues("author");
string[] description = form.GetValues("description");
DateTime uploaddate = form.GetValues("uploaddate");
DateTime expirydate = form.GetValues("expirydate");
string[] participationpoints = form.GetValues("participationpoints");
string[] contenttypeid = form.GetValues("contenttypeid");
try
{
avm.AddContent(postedFile, stream, name, author, description, uploaddate, expirydate, participationpoints, contenttypeid);
}
catch (Exception ex)
{
return RedirectToAction("Index", "Admin");
}
}
}
In my AdminViewModel I then called a method saved the associated metadata through my dbcontext and so the changes were saved to SQL storage and while the file was also written to blob storage.