无法使用 autodesk forge derivativesApi 翻译创建的对象

Unable to translate created object using autodesk forge derivativesApi

我试图在上传对象后对其进行翻译,但我一直收到 400 Bad Request 错误。

我正在使用 forge-api-nodejs-client

这是我的代码的样子

          var base64 = require('js-base64').Base64;

          objectsApi.uploadObject(
            bucket.bucketKey,
            file.originalname,
            file.size,
            file.buffer,
            {},
            oAuth2TwoLegged,
            credentials
          )
          .then(
            response => {
              const objectDetails = response.body;

              // objectId => urn:adsk.objects:os.object:d62db090-0c47-11e8-9a36-7bd06cedf058/Pawn.stl

              const job = {
                input: {
                  urn: base64.encode(objectDetails.objectId)
                },
                output: {
                  formats: [
                    {
                      type: "obj"
                    }
                  ]
                }
              };
              derivativesApi
                .translate(job, {}, oAuth2TwoLegged, credentials)
                .then(
                  data => {
                    res.send(data);
                  },
                  err => {
                    // it fails here with 400 status error
                    res.send(err);
                  }
                );
            },
            err => {
              res.send(err);
            }
          );

我的 job 对象看起来像这样:

{
  input:{
    urn: 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZDYyZGIwOTAtMGM0Ny0xMWU4LTlhMzYtN2JkMDZjZWRmMDU4L1Bhd24uc3Rs'
  },
  output: {
    formats: [
      type: "obj"
    ]
  }
}

回应

{
  statusCode: 400,
  statusMessage: "Bad Request"
}

您的负载不正确,应该如下所示:

{
  input: {
    urn: "...place your design url here ..."
  },
  output:{
    force: false, // true if you want to force regenerate the obj, after new model upload for ex (optional)
    formats: [{
      type: 'obj',
      advanced: {
        modelGuid: "...",  // model GUID, required
        objectIds: [-1]    // array of dbIds to export, required. Pass [-1] to export full model, or specific dbIds ex: [49, 56, ...]
      }
    }],
    destination: {
      region: 'us'  // default, optional can be ['us', 'emea']
    }
  }
})

您需要执行额外的 API 调用来检索模型 GUID:有关详细信息,请参阅 GET :urn/metadata

我还有一个使用 Forge NPM 完成创建存储桶以上传文件和翻译文件的整个过程的教程。我认为您遇到问题的部分是上传部分

检查这个 https://github.com/jaimerosales/modelderivative-nodejs-tutorial/blob/master/uploader.js#L145