【问题标题】:Why does Azure Media Services v3 job fail when submitting an encoded URL to JobInputHttp?向 JobInputHttp 提交编码 URL 时,为什么 Azure 媒体服务 v3 作业会失败?
【发布时间】:2020-10-15 21:44:33
【问题描述】:

向 JobInputHttp 类提交 url 以使用上传的视频作为媒体源时,如果由于文件名有空格而对 url 进行了编码,则作业会失败?

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

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

测试用例:

  • 文件名不带空格并符合命名约定 - 可以通过 AZM 资产查看
  • 文件名包含空格 - 不确定空格是否满足 AZM Asset naming conventions
    • 如果未编码则返回 500 错误
    • 当编码错误“尝试下载输入文件时,文件无法访问,请检查源的可用性”时,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

【问题讨论】:

    标签: c# azure azure-media-services


    【解决方案1】:

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

    我使用&lt;string&gt;.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 在提交之前没有被解码,因此无法找到视频源。

    我想我只需要提出问题就可以得到答案。现实生活中的橡皮鸭调试:)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      相关资源
      最近更新 更多