[英]C# Azure MediaServices uploading file throws an error
我正在使用MVC4测试项目尝试将文件上传到Azure媒体服务。
我可以创建我的CloudMediaContext罚款。 我还可以创建一个IAsset,并在其中创建一个IAssetFile。 但是,当我尝试向其中上传新文件时,出现以下异常:
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)
我不确定错误是否在于MVC4中,因为它无法从自己的目录上传文件? 根据错误,我缺少一些引用或程序集,但我添加的唯一东西是Azure.MediaServices的NuGet程序包,该程序包安装了Azure MediaServices .NET SDK ...
这是上传的HomeController代码:
[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 });
}
这是我的MediaServices类(正在做的工作)
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
}
由于某种原因,以下解决了我的问题。
在NuGet PackageManager控制台中,键入以下内容:
PM> Install-Package WindowsAzure.Storage
这似乎已经更新了Microsoft.WindowsAzure.Storage依赖关系,并允许我的程序正常工作。 非常奇怪,微软。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.