Why does Azure Media Services v3 job fail when submitting an encoded URL to JobInputHttp?

我的梦境 提交于 2020-12-15 05:58:06

问题


When submitting urls to the JobInputHttp class to use an uploaded video as a media source, the job fails if the url is encoded because the file name has spaces?

For encoding I am just using encodeURI() to replace the spaces character with %20 using JavaScript before sending it to the web server.

File is uploaded to blob storage from client side. I am able to view the video from azure portal so it is being uploaded correctly. After the video is uploaded a stream attempts to be created by sending the encoded url and filename of the uploaded file to the backend before submitting to Azure Media Services (AZM).

Test Cases:

  • Filename without spaces and meets naming conventions - Passes and viewable from AZM asset
  • Filename contains spaces - Unsure if spaces meeting AZM Asset naming conventions
    • Returns 500 Error if not encoded
    • Job fails in azure portal when encoded with error "While trying to download the input files, the files were not accessible, please check the availability of the source", screenshot below.

Failed Job Screenshot

Current Code:

        private async Task<Job> SubmitJobAsync(IAzureMediaServicesClient client,
        string resourceGroup,
        string accountName,
        string transformName,
        string outputAssetName,
        string jobName,
        string url)
    {
        // This example shows how to encode from any HTTPs source URL - a new feature of the v3 API.  
        // Change the URL to any accessible HTTPs URL or SAS URL from Azure.
        JobInputHttp jobInput =
            new JobInputHttp(files: new[] { url });

        JobOutput[] jobOutputs =
        {
            new JobOutputAsset(outputAssetName),
        };

        // In this example, we are assuming that the job name is unique.
        //
        // If you already have a job with the desired name, use the Jobs.Get method
        // to get the existing job. In Media Services v3, the Get method on entities returns null 
        // if the entity doesn't exist (a case-insensitive check on the name).
        Job job = await client.Jobs.CreateAsync(
            resourceGroup,
            accountName,
            transformName,
            jobName,
            new Job
            {
                Input = jobInput,
                Outputs = jobOutputs,
            });

        return job;
    }

Example using Azure Media Services

  • Git Files

Example using JobInputHttp Class


回答1:


Answer: The encodeURI() function was also encoding special characters within the Shared Access Signature (SAS) token submitted in the url.

I tested the submission using <string>.replaceAll(' ', '%20') and was able to get a passing AZM job. I ran the full URL through encodeURI() and compared the SAS Tokens and realized it changed %253D to %25253D based on standard HTML encoding.

Testing code from MDN

const encoded = encodeURI("%253D");
console.log('Encoded: ', encoded);
// expected output: "%25253D"

try {
  console.log('Decoded', decodeURI(encoded));
  // expected output: "%253D"
} catch (e) { // catches a malformed URI
  console.error(e);
}

// output
//"Encoded: " "%25253D"
//"Decoded" "%253D"

Because the URL was not being decoded before being submitted it was not able to locate the video source.

I guess I just needed to ask the question to get the answer. Real-life rubber ducky debugging :).



来源:https://stackoverflow.com/questions/64362008/why-does-azure-media-services-v3-job-fail-when-submitting-an-encoded-url-to-jobi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!