无法使用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"
}

我还使用Forge npm进行了一个教程,以执行创建存储桶以上传文件和翻译它的整个过程。我认为您遇到问题的部分是上传部分

检查此https://github.com/jaimerosales/modelderivativativativativativativation-nodejs-tutorial/blob/master/uploader.js#l145

您的有效载荷不正确,应如下所示:

{
  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有关更多详细信息

最新更新