Skip to main content
Question

File download does not work using API

  • May 22, 2025
  • 1 reply
  • 30 views

Forum|alt.badge.img
I used this code
-----------------------------------------------------------------------------
const BoxSDK = require('./node_modules/box-node-sdk');
 
const sdkConfig = require('./config.json');
const sdk = BoxSDK.getPreconfiguredInstance(sdkConfig);

 

const client = sdk.getAppAuthClient('enterprise');

 

const fs = require('fs');
client.files.getReadStream('fileID', null, function(error, stream) {

 

if (error) {
// handle error
}

 

console.log(stream);
// write the file to disk
constoutput=fs.createWriteStream('sample.txt');
stream.pipe(output);

});

------------------------------------------------------------------

but an error occurs

undefined
/home/mg0x42y7214f7c/BOX-app/HTML/node_modules/bluebird/js/release/async.js:49
fn = function () { throw arg; };
^

TypeError: Cannot read property 'pipe' of undefined

I cant download file and i want help.

1 reply

Forum|alt.badge.img

Hi

I think you will get this error when the fileID you are trying to read either doesn't exist or the user executing the call does not have access to it.

If you add some error handling logic you will probably see a 404 status code being returned.

Hope this helps

Peter Christensen, Platform Solutions Engineer, Box