简体   繁体   中英

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

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

Example using JobInputHttp Class

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 :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM