Skip to content

if using Forge SDK 0.9.0, uploadObject failed with the error "The "chunk" argument must be of type string or an instance of Buffer" #31

@xiaodongliang

Description

@xiaodongliang

from SO post: https://stackoverflow.com/questions/72420952/forge-design-automation-revit-tutorial-error

In current version, the tutorial uses version 0.8.5 of Forge SDK (https://www.npmjs.com/package/forge-apis). if upgrading to 0.9.0, the exception will occur at
https://github.com/Autodesk-Forge/learn.forge.designautomation/blob/nodejs/routes/DesignAutomation.js#L508-L511

i.e. if createeadStream, it will cause exception. After switching to readFileSync, it works now.

` // 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);

    }

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions