gpt4 book ai didi

C# Azure MediaServices 上传文件引发错误

转载 作者:行者123 更新时间:2023-12-03 03:17:30 25 4
gpt4 key购买 nike

我正在使用 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 依赖项并允许我的程序正常工作。很奇怪,微软。

关于C# Azure MediaServices 上传文件引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21662238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com