0
votes

Hey I use the Box API and I successfull to upload my files but they are stored at the app storage folder. If you would go to the admin-console and then click the folder Icon you can see the admin folder and then the folder of the created app. How can I change the path that every upload will go to the admin folder that if I relog to box.com I would see all my files in the home folder instead of going to the admin-console every time?

1

1 Answers

2
votes

This should work.

    var client = sdk.getAppAuthClient('enterprise', ENTERPRISE_ID);

   //filter_term == admin to share the folder with
   client.enterprise.getUsers({filter_term: '[email protected]'}, function(err, users) {
   var userId = users.entries[0].id;
   client.folders.create('0', 'New Folder', function(err, newFolder) {
    client.collaborations.createWithUserID(userId, newFolder.id, client.collaborationRoles.VIEWER, function(err, collaboration) {
        console.log(err);

        var fileData = fs.createReadStream('/users/kdomen/Downloads/test.txt')
        client.files.uploadFile(newFolder.id, 'test.txt', fileData, function(err, file) {
          if (err){
            console.log('err: ' + err);
          }
          else{
            console.log('file uploaded: ' + file);  
          }
        });
    });
});
});