将编码的URL提交给JobInputHttp时,为什么Azure Media Services v3作业会失败?

问题描述

在将URL提交给JobInputHttp类以使用上传的视频作为媒体源时,如果URL编码是因为文件名中有空格,则作业将失败?

对于编码,我只是在将其发送到Web服务器之前,使用JavaScript使用encodeURI()将空格字符替换为%20。

文件从客户端上传到Blob存储。我可以从azure门户查看视频,因此可以正确上传。视频上传后,尝试通过将上传文件的编码url和文件名发送到后端,然后再提交到Azure Media Services(AZM),来创建流。

测试用例:

  • 文件名不带空格且符合命名约定-通过并可以从AZM资产查看
  • 文件名包含空格-不确定空格是否满足AZM Asset naming conventions
    • 如果未编码,则返回500错误
    • Job在azure门户中失败,并带有错误“在尝试下载输入文件时,文件无法访问,请检查源的可用性”,下面的屏幕快照。

Failed Job Screenshot

当前代码:

        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

解决方法

答案:encodeURI()函数还在URL中提交的Shared Access Signature (SAS)令牌内对特殊字符进行了编码。

我使用<string>.replaceAll(' ','%20')测试了提交内容,并获得了合格的AZM工作。我通过encodeURI()运行了完整的URL,并比较了SAS令牌,并意识到它基于standard HTML encoding%253D更改为%25253D

测试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"

由于未在提交URL之前对其进行解码,因此无法找到视频源。

我想我只需要问这个问题就能得到答案。现实生活中的橡皮鸭调试:)。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...