我正在尝试将视频上传到Windows Azure媒体服务。使用Microsoft提供的示例我收到错误System.Collections.ListDictionaryInternal
。但是,当我将此行从var uploadFilePath = Path.GetFileName(FileUpload1.PostedFile.FileName);
更改为var uploadFilePath = Path.GetFileName(@"c:\video\ocean.mp4");
时。文件上传,它工作正常。
<code>
try
{
var uploadFilePath = Path.GetFileName(FileUpload1.PostedFile.FileName);
var context = new CloudMediaContext("123media", "###############");
var uploadAsset = context.Assets.Create(Path.GetFileNameWithoutExtension(uploadFilePath), AssetCreationOptions.None);
var assetFile = uploadAsset.AssetFiles.Create(Path.GetFileName(uploadFilePath));
assetFile.Upload(uploadFilePath);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch (AggregateException ex)
{
StatusLabel.Text = ex.Data.ToString();
}
<form id="form1" enctype="multipart/form-data" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" CssClass="btn-button" runat="server" Width="325px" />
<asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" />
<br />
<br />
<asp:Label runat="server" id="StatusLabel" text="Upload status: " />
</div>
</form>
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at Microsoft.WindowsAzure.MediaServices.Client.AssetFileData.Upload(String path) at WIT.test3.UploadButton_Click(Object sender, EventArgs e) in c:\Users\Dan\Documents\Visual Studio 2013\Projects\WIT\WIT\test3.aspx.cs:line 37
答案 0 :(得分:1)
这是FileName HttpPostedFile的PostedFile属性(其类型是FileUpload控件的save the uploadedfile属性)实际上是完全限定的名称服务器上的文件 ,不。
您必须在本地首先my Sample MVC based project使用相同的名称,然后将其传递给AssetFile对象进行上传。
有些人尝试修复代码:
try
{
var fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
var serverFileName = Server.MapPath("~/" + fileName);
FileUpload1.PostedFile.SaveAs(serverFileName);
var context = new CloudMediaContext("123media", "###############");
var uploadAsset = context.Assets.Create(Path.GetFileNameWithoutExtension(fileName), AssetCreationOptions.None);
var assetFile = uploadAsset.AssetFiles.Create(fileName);
assetFile.Upload(serverFileName);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch (AggregateException ex)
{
StatusLabel.Text = ex.Data.ToString();
}
你能引用一下你从哪里得到这个示例代码?顺便说一句,你可以得到{{3}}。我大约3个月前更新了它,所以一定要工作。