Forge Design Automation Revit 教程错误

Forge Design Automation Revit Tutorial Error

我正在尝试 Revit 设计自动化教程。 我收到以下错误。 谁能帮我解决这个错误。

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of ReadStream
at new NodeError (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\lib\internal\errors.js:372:5)
at write_ (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\lib\_http_outgoing.js:742:11)
at ClientRequest.end (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\lib\_http_outgoing.js:855:5)
at Request._end (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\node\index.js:1282:9)
at Request.end (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\node\index.js:1000:8)
at c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\request-base.js:282:12
at new Promise (<anonymous>)
at RequestBase.then (c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\superagent\lib\request-base.js:264:31)
at c:\Users\roshan.kerketta\Desktop\Digital\Forge\ModelDesignAutomation\SampleDesignAutomation\node_modules\forge-apis\src\ApiClient.js:394:7
at processTicksAndRejections (node:internal/process/task_queues:96:5) {code: 'ERR_INVALID_ARG_TYPE', statusCode: undefined, stack: 'TypeError [ERR_INVALID_ARG_TYPE]: The "chunk"…ions (node:internal/process/task_queues:96:5)', message: 'The "chunk" argument must be of type string …nt8Array. Received an instance of ReadStream', toString: ƒ, …}

I want to understand what the error means, so it could help me fix the error., though it might be basic.

如果您的目标是了解这个特定的错误,那么您可以阅读 question/answer 最好的地方 asked/explained。然而,由于这是来自 Forge 的 nodejs api,我认为你没有编写这段代码,你不应该关心它。

我最好的猜测是您以某种方式设法将 nodejs 软件包 forge-api 升级到 0.9.0,而教程的其余部分 repo/code 与它不兼容。您可以使用以下命令进行检查:

cd {repo_folder}
npm ls -depth=0

您应该会看到以下结果:

├── autodesk.forge.designautomation@3.0.5
├── body-parser@1.20.0
├── cookie-session@1.4.0
├── express@4.18.1
├── forge-apis@0.8.6
├── form-data@4.0.0
├── multer@1.4.4
└── socket.io@4.5.1

如果您的 forge-apis 显示的是 0.9.0 而不是 0.8.6,则说明了您遇到的错误。要降级它,您可以删除 node_modules 文件夹,再次撤消对 package.json and/or package-lock.json 和 运行 npm install 的任何更改。

或者,您也可以显式降级 forge-api 模块。

cd {repo_folder}
npm install forge-apis@0.8.6 -save
npm ls -depth=0

感谢 Rahul 发现问题!我可以在 0.9.0 中重现@JohnKuldeepRoshanKerketta 在 Forge SDK (forge-apis) 中的体验。根据错误提示,我更新了 tutorial code(line 509,510) 以使用 readFile,而不是文件流。现在它适用于 0.9.0.

我发布了 Issue with tutorial https://github.com/Autodesk-Forge/learn.forge.designautomation/issues/31

// 2. upload inputFile
const inputFileNameOSS = `${new Date().toISOString().replace(/[-T:\.Z]/gm, '').substring(0,14)}_input_${_path.basename(req.file.originalname)}`; // avoid overriding

try {
    //let contentStream = _fs.createReadStream(req.file.path);

    let fileContent = _fs.readFileSync(req.file.path);

    await new ForgeAPI.ObjectsApi().uploadObject(bucketKey, inputFileNameOSS, req.file.size, fileContent, {}, req.oauth_client, req.oauth_token);
}