0

我正在尝试使用 Autodesk.Forge .NET API 方法 GetDerivativeManifest (C#) 下载从 SVF 文件生成的 OBJ 文件。OBJ 文件已成功创建。但是,该方法没有提供可用于检索文件并将其保存在本地的 Stream。

如何获取 OBJ 文件?

4

1 回答 1

0

我没有准备好给你的 C# 示例,但我在 Node.js SDK 中遇到了同样的问题。我通过自己实现 REST 调用来解决问题:

download (token, urn, derivativeURN, opts = {}) {

  // TODO SDK KO
  //this._APIAuth.accessToken = token
  //
  //return this._derivativesAPI.getDerivativeManifest(
  //  urn,
  //  derivativeURN,
  //  opts)

  return new Promise((resolve, reject) => {

    const url =
      `${DerivativeSvc.SERVICE_BASE_URL}/designdata/` +
      `${encodeURIComponent(urn)}/manifest/` +
      `${encodeURIComponent(derivativeURN)}`

    request({
      url: url,
      method: 'GET',
      headers: {
        'Authorization': 'Bearer ' + token.access_token
      },
      encoding: null
    }, function(err, response, body) {

      try {

        if (err) {

          return reject(err)
        }

        if (response && [200, 201, 202].indexOf(
            response.statusCode) < 0) {

          return reject(response.statusMessage)
        }

        if (opts.base64) {

          resolve(bufferToBase64(body))

        } else {

          resolve(body)
        }

      } catch(ex) {

        console.log(ex)

        reject(ex)
      }
    })
  })
}

以下是我在端点中调用该方法的方式:

/////////////////////////////////////////////////////////
// GET /download
// Download derivative resource
//
/////////////////////////////////////////////////////////
router.get('/download', async (req, res) => {

  try {

    const filename = req.query.filename || 'download'

    const derivativeUrn = req.query.derivativeUrn

    // return base64 encoded for thumbnails
    const base64 = req.query.base64

    const urn = req.query.urn

    const forgeSvc = ServiceManager.getService(
      'ForgeSvc')

    const token = await forgeSvc.get2LeggedToken()

    const derivativesSvc = ServiceManager.getService(
      'DerivativesSvc')

    const response = await derivativesSvc.download(
      token, urn, derivativeUrn, {
        base64: base64
      })

    res.set('Content-Type', 'application/octet-stream')

    res.set('Content-Disposition',
      `attachment filename="${filename}"`)

    res.end(response)

  } catch (ex) {

    res.status(ex.statusCode || 500)
    res.json(ex)
  }
})

希望有帮助

于 2017-09-22T09:38:32.360 回答