I am trying to upload a video to Windows Azure Media Services. Using the example that Microsoft gave I am getting an error saying System.Collections.ListDictionaryInternal
. However when I change this line from var uploadFilePath = Path.GetFileName(FileUpload1.PostedFile.FileName);
to var uploadFilePath = Path.GetFileName(@"c:\video\ocean.mp4");
. The file uploads and it works fine.
<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
This is sick... FileName property of the HttpPostedFile (of which type is the PostedFile property of the FileUpload control) is actually the Fully Qualified Name of the file on the client, not on the server.
You have to actually first save the uploadedfile locally, with same name, then pass it to the AssetFile object for upload.
Some try to fix the code:
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();
}
Can you quote where did you get this sample code from? BTW, you can get my Sample MVC based project. I updated it about 3 months ago, so must be working.