Azure媒体服务错误400

时间:2017-04-30 16:34:25

标签: c# azure azure-media-services azure-webjobssdk

我正在构建一个应用程序,我正在尝试编写一个webjob 拿一个mp4文件我已经上传到blob存储并创建一个资产然后我可以编码并准备使用azure媒体服务流。

public class Functions
    {
        // This function will get triggered/executed when a new message is written 
        // on an Azure Queue called queue.
        static string accName = "copied from portal ";
        static string accKey = "as above";
        static CloudMediaContext context = new CloudMediaContext(accName,accName);
        // Use the cached credentials to create CloudMediaContext.
        //static CloudMediaContext context = new CloudMediaContext(accName,accKey);
        public static void ProcessVideo(
        [QueueTrigger("videorequest")] VideoBlobInformation blobInfo,
        [Blob("{ProfileId}/{BlobName}", FileAccess.Read)] Stream input,
        [Blob("{ProfileId}/{BlobNameWithoutExtension}_stream.mp4")] CloudBlockBlob outputBlob)
        {
            VideoBlobInformation b = blobInfo;
            using (Stream output = outputBlob.OpenWrite())
            {
                ConvertAndPrepareVideo(b,input, output);
            }
            // Entity Framework context class is not thread-safe, so it must
            // be instantiated and disposed within the function.
            using (impulsevidContext db = new impulsevidContext())
            {
                //var id = blobInfo.ProfileId;
                //Video ad = db.Videos.Find(id);
                //if (ad == null)
                //{
                  //  throw new Exception(String.Format("AdId {0} not found, can't create thumbnail", id.ToString()));
                //}
                //ad.StreamUrl = outputBlob.Uri.ToString();
                //db.SaveChanges();
            }
            
        }
        public static void ConvertAndPrepareVideo(VideoBlobInformation info,Stream input, Stream output)
        {
            var storageAccount = new CloudStorageAccount(new StorageCredentials("accnameofstorage", "storage account associated with azure media services"), true);
            //output all webjob input blobs into a container -mediacontroller- 
            var cloudBlobClient = storageAccount.CreateCloudBlobClient();
            var mediaBlobContainer = cloudBlobClient.GetContainerReference("impfile");
            mediaBlobContainer.CreateIfNotExists();
            IAsset sourceAsset = context.Assets.Where(a => a.Id == info.VideoId).First();
        }
我正在使用我上传到的单个存储帐户。 无论我尝试使用此行

,我都会收到此错误400

IAsset sourceAsset = context.Assets.Where(a => a.Id == info.VideoId).First();

导致此日志错误

  

Microsoft.Azure.WebJobs.Host.FunctionInvocationException:执行函数时出现异常:Functions.ProcessVideo ---&gt; System.Net.WebException:远程服务器返回错误:(400)错误请求。    在System.Net.WebClient.UploadValues(Uri地址,String方法,NameValueCollection数据)    在System.Net.WebClient.UploadValues(String address,String method,NameValueCollection data)    在Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider。&lt;&gt; c__DisplayClass47_2.b__0()    在Microsoft.Practices.TransientFaultHandling.RetryPolicy。&lt;&gt; c__DisplayClass1.b__0()    在Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction [TResult](Func 1 func) at Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction(Action action) at Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider.RefreshToken() at Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider.GetAccessToken() at Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider.GetAuthorizationHeader() at Microsoft.WindowsAzure.MediaServices.Client.OAuth.OAuthDataServiceAdapter.AddAccessTokenToRequest(WebRequest request) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory.<>c__DisplayClass21_0.<GetAccountApiEndpoint>b__0() at Microsoft.Practices.TransientFaultHandling.RetryPolicy.<>c__DisplayClass1.<ExecuteAction>b__0() at Microsoft.WindowsAzure.MediaServices.Client.TransientFaultHandling.MediaRetryPolicy.ExecuteAction[TResult](Func 1 func)    在Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction(Action action)    在Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory.GetAccountApiEndpoint(OAuthDataServiceAdapter dataServiceAdapter,ServiceVersionAdapter versionAdapter,Uri apiServer,UserAgentAdapter userAgentAdapter,IWebRequestAdapter clientRequestIdAdapter)    在Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory。&lt;&gt; c__DisplayClass24_0.b__0()    在Microsoft.WindowsAzure.MediaServices.Client.Cache 1.GetOrAdd(String key, Func 1 valueFactory,Func 1 expirationFactory) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory.CreateAzureMediaServicesEndPoint(Uri azureMediaServicesEndpoint, MediaContextBase mediaContext) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory..ctor(Uri azureMediaServicesEndpoint, CloudMediaContext mediaContext) at Microsoft.WindowsAzure.MediaServices.Client.CloudMediaContext.get_MediaServicesClassFactory() at Microsoft.WindowsAzure.MediaServices.Client.AssetCollection.<.ctor>b__2_0() at System.Lazy 1.CreateValue()    在System.Lazy 1.LazyInitValue() at System.Lazy 1.get_Value()    在Microsoft.WindowsAzure.MediaServices.Client.AssetCollection.get_Queryable()    在Microsoft.WindowsAzure.MediaServices.Client.BaseCollection 1.get_Provider() at System.Linq.Queryable.Where[TSource](IQueryable 1 source,Expression 1 predicate) at VideoProcess.Functions.ConvertAndPrepareVideo(VideoBlobInformation info, Stream input, Stream output) at VideoProcess.Functions.ProcessVideo(VideoBlobInformation blobInfo, Stream input, CloudBlockBlob outputBlob) at lambda_method(Closure , Functions , Object[] ) at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker 1.InvokeAsync(TReflected instance,Object [] arguments)    在Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.d__8.MoveNext()    ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__22.MoveNext()    ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)    在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__21.MoveNext()    ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__19.MoveNext()    ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)    在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext()    ---内部异常堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext()    ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__10.MoveNext()

1 个答案:

答案 0 :(得分:0)

context = new CloudMediaContext(new MediaServicesCredentials(                             accName,                             accKey)); 应该在ConvertAndPrepareVideo方法中设置,而不是在

之外