0

我正在尝试将视频上传到 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

4

1 回答 1

1

这很恶心...... HttpPostedFile的FileName属性(其类型是FileUpload控件的PostedFile属性)实际上是客户端上文件的完全限定名称,而不是服务器上。

实际上,您必须先将上传的文件以相同的名称保存在本地,然后将其传递给 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();
    }

你能引用你从哪里得到这个示例代码吗?顺便说一句,你可以得到我的基于 MVC 的示例项目。我大约 3 个月前更新了它,所以必须工作。

于 2014-12-18T22:14:21.013 回答