0

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);
}
});
t33n
  • 270
  • 1
  • 3
  • 17

1 Answers1

2

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.

kendomen
  • 770
  • 6
  • 13
  • 1
    omg yes you are right. this is very mystical :D Is there a way to upload always with the administrator that I can see the files directly when I logged in to my box account? – t33n Aug 03 '17 at 13:32
  • 1
    You can add the admin as a collaborator to a folder created in the service acccount. – kendomen Aug 03 '17 at 13:34
  • 1
    thank you for the help dude :) but where is this service account area.- I already searched at the normal box.com area and in the developer area but there are so many options not sure which you mean. can you send me a URL or screen please that I see what you mean. would be awesome – t33n Aug 03 '17 at 13:47
  • If you post this as a new question, I can post the solution as code. Thanks! – kendomen Aug 03 '17 at 17:19
  • https://stackoverflow.com/questions/45494079/box-api-upload-files-to-admin-account-instead-of-app – t33n Aug 03 '17 at 20:37