Forge Design Automation Revit Tutorial Error

I am trying the Design Automation Tutorial for Revit. I am getting the following error. Can someone help me fix this error.

enter image description here

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: ƒ, …}

Upvotes: 0

Views: 191

Answers (2)

Xiaodong Liang
Xiaodong Liang

Reputation: 2196

Thanks Rahul for spotting the issue! I can reproduce what @JohnKuldeepRoshanKerketta experienced in Forge SDK (forge-apis) in 0.9.0. By the hint of error, I updated the tutorial code(line 509,510) to use readFile, instead of file stream. Now it works well with 0.9.0.

I posted the 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);
}

Upvotes: 0

Rahul Bhobe
Rahul Bhobe

Reputation: 4451

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

If your goal is to understand this specific error, then you can read this question/answer where it is best asked/explained. However since this is coming from Forge's nodejs apis, I think you did not write this code and you should not be concerned with it.

My best guess is you have somehow managed to upgrade the nodejs package forge-api to 0.9.0 and the rest of the tutorial repo/code is not compatible with it. You can check this with the following command:

cd {repo_folder}
npm ls -depth=0

You should see the following result:

├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

If your forge-apis is showing 0.9.0 instead of 0.8.6, then it explains the error you have. To downgrade it, you can either delete your node_modules folder, undo any changes to package.json and/or package-lock.json and run npm install again.

Alternatively you can also explicitly downgrade the forge-api module.

cd {repo_folder}
npm install [email protected] -save
npm ls -depth=0

Upvotes: 0

Related Questions