0

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: ƒ, …}
Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
  • There isn't enough information to help you with this question. Kindly share more details on which tutorial you are using (at this point there are many tutorials). I'd also suggest to go though the instructions and see what you might have missed. This may turn out to be something basic and esential that you missed. – Rahul Bhobe May 29 '22 at 05:18
  • @RahulBhobe I used the following tutorial [link](https://learnforge.autodesk.io/#/tutorials/modifymodels). I want to understand what the error means, so it could help me fix the error., though it might be basic. – John Kuldeep Roshan Kerketta May 29 '22 at 05:31
  • 1
    @JohnKuldeepRoshanKerketta, I tried with the tutorial sample, it works well. My test is uploaded to https://myshare.autodesk.com/:v:/g/personal/xiaodong_liang_autodesk_com/EXopNPtwmNhPkrjI4j4xiqcBfKOWNXf250kyFcnT8t5nQQ?e=NCkQPD – Xiaodong Liang May 30 '22 at 01:27
  • 1
    @JohnKuldeepRoshanKerketta The error in your test shows chunk , but the tutorial does not nothing with chunk. It is direct uploading of whole file. So I guess you are trying to add some of your own code to upload big file in chunk? Could you clarify and share us with demo code ? – Xiaodong Liang May 30 '22 at 01:28

2 Answers2

0

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:

├── 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

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 forge-apis@0.8.6 -save
npm ls -depth=0
Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
0

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);
}
Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14