Search code examples
c#.netexceptionvideo-processingazure-media-services

Azure Media Services v3 Assets.ListContainerSasAsync returns ApiErrorException


I'm calling Assets.ListContainerSasAsync from Azure Media Services v3 in (.net), however, APIErrorException is returned with no apparent reason. I've triple-checked I've got valid config.ResourceGroup, config.AccountName, and assetName parameters.

Code:

AssetContainerSas assetContainerSas = await client.Assets.ListContainerSasAsync(config.ResourceGroup, config.AccountName, assetName, permissions: AssetContainerPermission.Read, expiryTime: DateTime.UtcNow.AddYears(1).ToUniversalTime());

Exception:

-       $exception  {"Operation returned an invalid status code 'InternalServerError'"} Microsoft.Azure.Management.Media.Models.ApiErrorException
+       Body    {Microsoft.Azure.Management.Media.Models.ApiError}  Microsoft.Azure.Management.Media.Models.ApiError
+       Data    {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
        HResult -2146233088 int
        HelpLink    null    string
-       InnerException  null    System.Exception
-       Static members      
+       Non-Public members      
        Message "Operation returned an invalid status code 'InternalServerError'"   string
+       Request {Microsoft.Rest.HttpRequestMessageWrapper}  Microsoft.Rest.HttpRequestMessageWrapper
-       Response    {Microsoft.Rest.HttpResponseMessageWrapper} Microsoft.Rest.HttpResponseMessageWrapper
        Content "{\r\n  \"error\": {\r\n    \"code\": \"InternalServerError\",\r\n    \"message\": \"The server encountered an internal error. Please try again later.\"\r\n  }\r\n}"   string
+       Headers Count = 17  System.Collections.Generic.IDictionary<string, System.Collections.Generic.IEnumerable<string>> {System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>}
        ReasonPhrase    "Internal Server Error" string
        StatusCode  InternalServerError System.Net.HttpStatusCode
        Source  "Microsoft.Azure.Management.Media"  string
        StackTrace  "   at Microsoft.Azure.Management.Media.AssetsOperations.<ListContainerSasWithHttpMessagesAsync>d__10.MoveNext()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Azure.Management.Media.AssetsOperationsExtensions.<ListContainerSasAsync>d__11.MoveNext()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at App.MediaLibrary.Service.Services.AzureMediaServicesService.<GetVideoUrlsAsync>d__10.MoveNext() in C:\\Users\\Martin\\Documents\\Projects\\x-a\\b\\c\\MediaLibrary\\Service\\Services\\AzureMediaServicesService.cs:line 108"   string
+       TargetSite  {Void MoveNext()}   System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
+       Static members      
+       Non-Public members      

Solution

  • The issue is likely related to the expiry time. According to https://learn.microsoft.com/en-us/rest/api/media/assets/listcontainersas#request-body the expiryTime must be less than 24 hours. For long lived SAS URLs, please use the Storage API.