Box API upload files to admin account instead of APP

江枫思渺然 提交于 2019-12-25 15:54:51

问题


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:


This should work.

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

   //filter_term == admin to share the folder with
   client.enterprise.getUsers({filter_term: 'ken.domen@nike.com'}, 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);  
          }
        });
    });
});
});


来源:https://stackoverflow.com/questions/45494079/box-api-upload-files-to-admin-account-instead-of-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!