Search code examples
azureazure-media-services

Azure Media Services Transient Error On upload


I'm getting the following when I upload via C# api code. (It seems to work fine from the portal)

TransientSystem : A transient error has occurred. We apologize for the inconvenience. Please try again.

I can't find anything about this and obviously it doesn't tell me anything.

Here's my code:`var account = GetAzureAccount(); var client = account.CreateCloudBlobClient();

        var sourceContainer = await GetAzureContainer(account, ResourceUtilities.VideoResources, false);

        var sourceBlob = GetBlockBlob(sourceContainer, videoResource);

        var context = GetMediaContext();
        IAsset asset = context.Assets.Create(GetAzureBlobName(videoResource), AssetCreationOptions.None);

        try
        {
            IAccessPolicy writePolicy = context.AccessPolicies.Create("writePolicy", TimeSpan.FromHours(24), AccessPermissions.Write);
            ILocator destinationLocator = context.Locators.CreateLocator(LocatorType.Sas, asset, writePolicy);

            // Get the asset container URI and Blob copy from mediaContainer to assetContainer. 
            string destinationContainerName = (new Uri(destinationLocator.Path)).Segments[1];

            CloudBlobContainer assetContainer = client.GetContainerReference(ResourceUtilities.MediaAssets);
            if (assetContainer.CreateIfNotExists())
            {
                assetContainer.SetPermissions(new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Off
                });
            }

            var assetFile = asset.AssetFiles.Create(sourceBlob.Name + "-source");
            CopyBlob(sourceBlob, assetContainer);
            assetFile.ContentFileSize = sourceBlob.StreamWriteSizeInBytes;
            assetFile.Update();
            destinationLocator.Delete();
            writePolicy.Delete();

            //Now encode it
            IJob job = context.Jobs.Create("Media Encoder Standard");
            var processor = GetLatestMediaProcessorByName(context, "Media Encoder Standard");
            var task = job.Tasks.AddNew("Encode " + videoResource.FileName, processor, "H264 Multiple Bitrate 720p", TaskOptions.None);

            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew(System.IO.Path.GetFileNameWithoutExtension(videoResource.FileName) + "-production" + System.IO.Path.GetExtension(videoResource.FileName), AssetCreationOptions.None);

            job.StateChanged += Job_StateChanged;
            await job.SubmitAsync();
            await job.GetExecutionProgressTask(CancellationToken.None);
            var finalAsset = job.OutputMediaAssets[0];
            if (job.State == JobState.Error)
            {
                await finalAsset.DeleteAsync();
                throw new InvalidOperationException(string.Join("\r\n", job.Tasks.SelectMany(t => t.ErrorDetails).Select(ed => ed.Message).ToArray()));
            }`

It goes on from there but fails on the job state erroring.

This is largely copied from samples so I'm at a loss. Anyone have suggestions?

Thanks!


Solution

  • For those that get this unhelpful error, I've determined you get it every time your asset doesn't have a blob in the asset container exactly named the same as that in the asset file. Fix it so the two are the same and it works.

    In my opinion this would work a lot better if the asset file was linked directly to a blob (and inherited from blob) so that this couldn't happen and there was a strong non-string link between the two (ie assetfile should just be an extension of the blob that underlies it)

    In the mean time a suggestion for the media team: make this throw a 404 file not found error with information and file name not found so it's possible to debug.