Search code examples
node.jsbox-apiboxapiv2

Box API can´t see my uploaded file


Related to this post Box API Node.js cant upload file 404 Error
I use the awnser code from below to auth my app It works with showing my username so auth successfull. If I look in my task manager I can see that there is outgoing traffic / uptime speed so the file will be uploaded in the function after the user check. And I also enter the else area so successfull upload. But if I look into my box website area I cant see the file. When I try to run the script again I get 409 error that the file already exist. Any Idea why I cant see the file at box.com? I manually added response and body for debug but they are not found. Also I enabled all scopes at developer area of box.com

Successfull log in to box.com - Your APP Name: xxxxxxx! file uploaded: [object Object] else body: undefined else response: undefined

This is my code

// BOX
var BoxSDK = require('box-node-sdk');



var config = require('config')





var sdk = new BoxSDK({ 
  clientID: config.get('boxAppSettings.clientID'),
  clientSecret: config.get('boxAppSettings.clientSecret'),
  appAuth: { 
    keyID: config.get('boxAppSettings.appAuth.publicKeyID'),
    privateKey: config.get('boxAppSettings.appAuth.privateKey'),
    passphrase: config.get('boxAppSettings.appAuth.passphrase'),
    expirationTime: 60,
    verifyTimestamp: false 
  } 
});


var client = sdk.getAppAuthClient('enterprise', "2xxxxxxxx5");


//Get some of that sweet, sweet data! 
client.users.get(client.CURRENT_USER_ID, null, function(err, currentUser) { 
  if(err) throw err; 
  console.log('Hello, ' + currentUser.name + '!'); 
});

    var fileData = fs.createReadStream('C:\\Exports\\box2.zip');
client.files.uploadFile('0', 'box2.zip', fileData, function(err, file, body, response) {
if (err){
console.log('err while upload file: ' + err)
console.log('if body: ' + body);
console.log('if response: ' + response);
}
else{
console.log('file uploaded: ' + file);
console.log('else body: ' + body);
console.log('else response: ' + response);
}
});

Solution

  • You're file uploaded to the service account created by the app. If you go to Admin Console -> Content Manager then type "automation" and select the automation user associated with your app, you'll see your content there.