I'm using an MVC4 test project to try to upload a file to the Azure Media Services.
I can create my CloudMediaContext fine. I can also create an IAsset and within that, an IAssetFile.
However, when I try to upload a new file to it, I get following exception:
Server Error in '/' Application.
Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=3.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I'm not sure whether the error lies within MVC4 for not being able to upload a file from its own directoy?
According to the error, I have some missing references or assemblies, but the only thing I've added is the NuGet package to Azure.MediaServices, which installed the Azure MediaServices .NET SDK...
This is the HomeController code for Upload:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
string localStorage = Server.MapPath("~/UploadedMedia");
string uploadedFileName = file.FileName;
if (!Directory.Exists(localStorage))
Directory.CreateDirectory(localStorage);
file.SaveAs(string.Format(@"{1}\{0}", file.FileName, localStorage));
_mediaServicesContext = new MediaServicesContext();
_mediaServicesContext.UploadFile(string.Format(@"{1}\{0}", file.FileName, localStorage));
return View(new UploadModel() { FileName = uploadedFileName, Post = true, Result = true });
}
And this is my MediaServices class (doing the work)
public class MediaServicesContext
{
#region ATTRIBUTES
private const string MEDIACONTEXTNAMEKEY = "MediaServiceAccountName";
private const string MEDIACONTEXTPASSKEY = "MediaServiceAccountAccessKey";
private const string MEDIASTORAGENAMEKEY = "StorageAccountName";
private const string MEDIASTORAGEPASSKEY = "StorageAccountAccessKey";
private readonly CloudMediaContext _mediaContext;
#endregion
#region CTORS
public MediaServicesContext()
{
_mediaContext = new CloudMediaContext(accountName: ConfigurationManager.AppSettings[MEDIACONTEXTNAMEKEY],
accountKey: ConfigurationManager.AppSettings[MEDIACONTEXTPASSKEY]);
}
#endregion
#region PROPERTIES
public CloudMediaContext MediaContext
{
get { return _mediaContext; }
}
#endregion
#region METHODS
public void UploadFile(string path)
{
// Create a .NET console app
// Set the project properties to use the full .NET Framework (not Client Profile)
// With NuGet Package Manager, install windowsazure.mediaservices
// add: using Microsoft.WindowsAzure.MediaServices.Client;
var uploadFilePath = path;
var context = _mediaContext;
var uploadAsset = context.Assets.Create(Path.GetFileNameWithoutExtension(uploadFilePath), AssetCreationOptions.None);
var assetFile = uploadAsset.AssetFiles.Create(Path.GetFileName(uploadFilePath));
assetFile.Upload(uploadFilePath);
}
#endregion
}