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:
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;
}
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.