"parameters.properties.archiveWindowLength must be a TimeSpan/Duration"

"parameters.properties.archiveWindowLength must be a TimeSpan/Duration"

我遇到了上述错误,其完整描述如下:

Error: Error parameters.properties.archiveWindowLength must be a TimeSpan/Duration. occurred in serializing the payload - {
  "archiveWindowLength": "PT30M",
  "assetName": "asset-OBS"
}.

我正在使用 nodeJS,从 azure 创建实时输出时出现此错误。

我的代码:

azureMediaServicesClient.liveOutputs.create(resourceGroup, accountName, liveEventName, liveOutputName, {
            archiveWindowLength : "PT30M",
            assetName : assetName,
 })

我试图搜索这个但没有找到任何支持的答案。

官方文档和nodejs sdk对archiveWindowLength的描述不一样。我猜测可能是nodejs sdk没有及时更新

最新的官方文档archiveWindowLength是string类型的,但是在nodejs sdk中还是moment.duration。您可以看到下面的屏幕截图。

所以要修改程序,使用moment.duration,需要通过const moment = require("moment");导入moment

您的代码应该如下所示:

const {AzureMediaServices} = require('azure-arm-mediaservices');
const msRestAzure = require('ms-rest-azure');
const msRest = require('ms-rest');
const azureStorage = require('azure-storage');
const moment = require("moment");

// endpoint config
// make sure your URL values end with '/'

const armAadAudience = "https://management.core.windows.net/";
const aadEndpoint = "https://login.microsoftonline.com/";
const armEndpoint = "";
const subscriptionId = "";
const accountName ="";
const location ="";
const aadClientId = "";
const aadSecret ="";
const aadTenantId ="";
const resourceGroup ="";

msRestAzure.loginWithServicePrincipalSecret(aadClientId, aadSecret, aadTenantId, {
environment: {
  activeDirectoryResourceId: armAadAudience,
  resourceManagerEndpointUrl: armEndpoint,
  activeDirectoryEndpointUrl: aadEndpoint
}
  }, async function(err, credentials, subscriptions) {
  if (err) return console.log(err);
  const azureMediaServicesClient = new AzureMediaServices(credentials, subscriptionId, armEndpoint, { noRetryPolicy: true });
  
  try {
    var a=  await azureMediaServicesClient.liveOutputs.create(resourceGroup, accountName, "jasonlive", "jasonliveoutput", {
        
        "archiveWindowLength" : moment.duration("PT30M"),
        "assetName" : "b-mp4-20210108-153238"
    })

    console.log(a)
    
  }
  catch(e){
      console.log(e.message)
  }
});

对我有用。

谢谢大家!谢谢杰森潘。

请注意,这里有一个全新的 Node.js 媒体服务 SDK - https://www.npmjs.com/package/@azure/arm-mediaservices

我没有时间构建任何新的实时流媒体样本,但我开始检查一些新的编码样本,这些样本展示了如何使用更新的 SDK。 很高兴得到社区对此 repo 中示例的任何支持!请让我知道您想贡献哪些内容。
https://github.com/Azure-Samples/media-services-v3-node-tutorials/tree/master

我现在有这个分支来处理一些新样本。请注意,目前只有 HelloWorld-listAssets 和 StreamFilesSample 已更新。 https://github.com/Azure-Samples/media-services-v3-node-tutorials/tree/updatedNodeSDK

更新: 我使用最新的媒体服务 Nodejs SDK 在 Typescript 中创建了新示例。看这里 https://github.com/Azure-Samples/media-services-v3-node-tutorials