[英]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?向 JobInputHttp 类提交 url 以使用上传的视频作为媒体源时,如果 url 被编码,因为文件名有空格,作业会失败?
For encoding I am just using encodeURI() to replace the spaces character with %20 using JavaScript before sending it to the web server.对于编码,我只是使用 encodeURI() 在将空格字符发送到 Web 服务器之前使用 JavaScript 用 %20 替换空格字符。
File is uploaded to blob storage from client side.文件从客户端上传到 blob 存储。 I am able to view the video from azure portal so it is being uploaded correctly.我可以从 azure 门户查看视频,因此可以正确上传。 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).视频上传后,在提交到 Azure 媒体服务 (AZM) 之前,会尝试通过将上传文件的编码 URL 和文件名发送到后端来创建流。
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.答案:encodeURI() 函数还在 url 中提交的共享访问签名 (SAS)令牌中编码特殊字符。
I tested the submission using <string>.replaceAll(' ', '%20')
and was able to get a passing AZM job.我使用<string>.replaceAll(' ', '%20')
测试了提交<string>.replaceAll(' ', '%20')
并且能够获得通过的 AZM 作业。 I ran the full URL through encodeURI() and compared the SAS Tokens and realized it changed %253D
to %25253D
based on standard HTML encoding .我跑通过是encodeURI()的完整URL,并比较了SAS令牌和实现它改变%253D
到%25253D
基于标准的HTML编码。
Testing code from MDN来自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.因为 URL 在提交之前没有被解码,所以无法定位视频源。
I guess I just needed to ask the question to get the answer.我想我只需要问这个问题就可以得到答案。 Real-life rubber ducky debugging :).真实的橡皮鸭调试:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.