Unable to upload a file to the right user
AnsweredHi,
We are able to upload a file to Box using a JWT, but the problem we are having is that when you create an App, it uploads the file to the App User rather than to the Main User. See below for a sample of our issue:
Sample upload of a file to the App User
Note that we would like the file (helloWorld.txt) to be uploaded into the user "Ranjit" inside the folder "Incomming" however the file as you can see, gets uploaded into the user "Jwt_Case_2" which is the name of the app. How do we get the file uploaded to the actual main user "Ranjit" and inside the folder "Incomming" say? Is there a specific API call to designate which user gets the file?
Thanks
Anthony
-
Hi ,
This is related to how JWT apps structure users. By default when you create a JWT app there is a programmatic user created to represent that app, which is called a service account. When you go through the JWT / OAuth 2 process and don't specify a specific user all file uploads will go directly into that service account. Let me show you how to swap this with some Java samples.
Let's say you go through the JWT auth process with the config file, obtained when you created your app, it may look something like this:
Reader reader = new FileReader(Config.config_path); BoxConfig boxConfig = BoxConfig.readFrom(reader); // Set cache info int MAX_CACHE_ENTRIES = 100; IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES); // Create new app enterprise connection object BoxDeveloperEditionAPIConnection client = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache);
The client variable will now reference the service account. This is what you're currently seeing. To instead set up that client variable to reference a user, replace that last line for client with something like this:
String userId = "14542659"; BoxDeveloperEditionAPIConnection client = new BoxDeveloperEditionAPIConnection(userId, DeveloperEditionEntityType.USER, boxConfig, accessTokenCache);
Each of the SDKs have a method for doing this, and if you want the specific code sample in your SDK language (if Java is not what you're using) just let me know and I can provide it.
You'll just need a few things to make this happen:
- The user ID that you want to upload the file to.
- The right settings in your app to access and make calls on behalf of users. Take a look at this guide that covers all of that (and how to set it) in your app. You'll need to have the "Users" scope set in your app configuration, set "Application Access" to enterprise, and under "Advanced Features" select the option for "Generate User Access Tokens". The guide will provide you with those details as well.
Please let me know if there are any issues that pop up.
- Jon
-
Jon,
Thank you so much for this detailed answer. Yes, we are doing this in C# (.NET) but we definitely get the "gist" of what you are explaining and I think you have given us everything we need to at least make an attempt at retrying this and being able to move forward again ... 🙂
Given the steps you have laid out and directions, we will try your suggested steps to get this working and if we run into further problems, I will reach out again.
Thanks again Jon
Anthony
Please sign in to leave a comment.
Comments
3 comments