Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

Can't upload to Azure Media Services - File Not Found

When I run the website locally, the video will upload to azure and I get a publish url. No problem. However, when I publish the website and then try to upload from there, I get this error:

Server Error in '/' Application. --------------------------------------------------------------------------------

c:V1.mp4 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.IO.FileNotFoundException: c:V1.mp4

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 



[FileNotFoundException: c:V1.mp4]
   Microsoft.WindowsAzure.MediaServices.Client.AssetFileData.UploadAsync(String path, BlobTransferClient blobTransferClient, ILocator locator, CancellationToken token) +499
   Microsoft.WindowsAzure.MediaServices.Client.<>c__DisplayClass1c.<UploadAsync>b__14(Task`1 t) +347
   System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke() +80
   System.Threading.Tasks.Task.Execute() +49

[AggregateException: One or more errors occurred.]
   System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) +3548265
   System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) +10487717
   System.Threading.Tasks.Task.Wait() +10
   Microsoft.WindowsAzure.MediaServices.Client.AssetFileData.Upload(String path) +90
   UploadTest.Upload.UploadVideoButton_Click(Object sender, EventArgs e) +101
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553594
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724`enter code here`

Upload.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Upload.aspx.cs" Inherits="UploadTest.Upload" %>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
    <asp:Button ID="UploadVideoButton" runat="server" Text="Upload The Video" OnClick="UploadVideoButton_Click" />
</asp:Content>

Upload.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.WindowsAzure.MediaServices.Client;

namespace UploadTest
{
    public partial class Upload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void UploadVideoButton_Click(object sender, EventArgs e)
        {
            CloudMediaContext context = new CloudMediaContext("<accountname>", "<accountkey>");
            var asset = context.Assets.Create("V1.mp4", AssetCreationOptions.None);
            var file = asset.AssetFiles.Create("V1.mp4");
            file.Upload(@"c:V1.mp4");
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you should use this to upload file by uploading the stream

public void UploadFileToAzure(Stream stream, string fileName, string contentType, 
    EContextType contextType) {
    if (stream == null)
        throw new ArgumentNullException("stream");

    if (fileName == null)
        throw new ArgumentNullException("fileName");

    CloudBlobContainer blobContainer = null;

    switch (contextType)
    {
        case EContextType.CloudStorage:
            blobContainer = AzureBlobUtil.InitializeBlob(Settings.AzureBlobStorageFileStorage, Settings.GetAzureDataConnectionString);
            break;
        default:
            blobContainer = AzureBlobUtil.InitializeBlob(Settings.AzureBlobStorageDocument, Settings.GetAzureDataConnectionString);
            break;
    }

    var blob = blobContainer.GetBlockBlobReference(fileName);
    blob.UploadFromStream(stream);

    blob.Metadata["FileName"] = fileName;
    blob.Metadata["IsArchived"] = false.ToString();
    blob.SetMetadata();
    // Set the properties
    blob.Properties.ContentType = contentType;

    blob.SetProperties();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...