How to upload documents to box as a user?
I'm a .NET developer who is tasked with migrating a number of document libraries from SharePoint to Box. As one would expect, the people who created the documents in question would still like to see their names listed as the author from the folder screen (of course, we can add metadata giving the name of the original author, and the in-file metadata still shows this information too). Here's pseudocode of what I tried to do, which so far as I can tell is the prescribed method for doing what we do:
- Create a box session, get metadata, etc.
For each individual file:
- Get the owner of the document that I'm trying to upload
- Using the owner or admin BoxClient object, add a collaboration of the user to the folder I want to add the doc to with "editor" rights
- Create a temporary as-user BoxClient object
- Add the file
- Using the owner/admin BoxClient object, remove the collaboration (unless, of course, the user in question ought to have access to the folder)
The problem that I run into is that when I add the collaboration, even if I specify that the status should be "accepted" (in Java I see there's an enum set up for it whereas in .NET you have to use a magic string but I'm positive that the wording/spelling I'm using is correct), if the user has not clicked the checkbox on their page (as far as I can tell) to accept all collaborations), it stays in pending, and when I go back in to change the status, I get an error saying that I can't change the status unless the status is currently marked as "pending", which it is.
Just to make sure we're all on the same page, if you create the userclient without adding the collaboration first, then the userclient won't even see the folder you want to write to, which is consistent with impersonation. The issue so far as I can see it is that due to what looks like a bug to me you can't add a collaboration with "accepted" status by default and there's no way to edit said status.
This seems like a pretty straightforward bug but hey, there's always the chance that I'm doing something wrong which is why I'm asking here. One thought I had was that this is stealthy an authorization issue but I'm not getting "forbidden" errors coming back, I'm getting "you're not in the right status" when you actually are.
-
This is somewhat by design; if a user has opted to not accept collaborations by default, you (the person inviting them to a folder) cannot force them to accept the collaboration when you create it. If you have the ability to As-User into their account, you should be able to do something like the following:
1) Create an As-User client for the user who needs to accept the collaboration and upload the file
2) Get a list of pending collaborations for that user and find the one you just created as the owner/admin
3) Accept the collaboration by setting the status to "accepted"
4) Upload the file(s) into the folder that you accepted the collaboration on
Please sign in to leave a comment.
Comments
2 comments