Nodejs SDK - Download File - access_denied_insufficient_permissions - Access denied
AnsweredWe are using the box nodejs sdk. I cannot download a file via API. Reading a directory / files is working great. When I will use the fileID to download the file to process it in my script I always get:
Error on Download Error: Unexpected API Response [403 Forbidden | 98ye1xgr46e3s3y2.015610c39a9363c40e9d179fae0f64a6c] access_denied_insufficient_permissions - Access denied - insufficient permission
Im using OAuth with the service Account and already have given write access to the folder. The user is also Co-Owner of the directory.
Im trying since hours to figure it out. What am I missing?
Code:
____________________________________
// Get Client
const sdkConfig = require('./box.config.json');
const sdk = BoxSDK.getPreconfiguredInstance(sdkConfig);
const client = sdk.getAppAuthClient('enterprise', sdkConfig.enterpriseID);
// Working Code for Folder-Contents
client.folders.getItems(folderId, { fields: 'id,type,name,modified_at,modified_by' });
// Download a File with fileId (!! Not working)
client.files.getReadStream(fileId, null, (error, stream) => {
if (error) {
console.error('Error on Download', error.toString());
return;
}
// write the file to disk
const output = fs.createWriteStream(targetPath);
stream.pipe(output);
});
Post is closed for comments.
Comments
1 comment