Join BoxWorks in San Francisco Nov 12-13! Keynotes, product demos, and Box Master Classes. Reserve your spot!

Upload to personal account

Answered
New post

Comments

6 comments

  • Official comment
    Alex Novotny

    Hey! 

    Can you send me a code example of what you are doing to upload content? 

    Thanks, 

    Alex, Box Developer Advocate

    Comment actions Permalink
  • Matheus Cruz

    Hey Alex,

    I'm using the oficial .NET sdk.

    My app is authenticated and is App Access Level and is using OAuth 2.0 Credentials with public key.

    Documentation: https://github.com/box/box-windows-sdk-v2

    using (FileStream stream = new FileStream(name, FileMode.Open))
    {
    BoxFileRequest req = new BoxFileRequest()
    {
    Name = name,
    Parent = new BoxRequestEntity() { Id = folderId }
    };

    newFile = await _boxCliente.FilesManager.UploadAsync(req, stream);
    }

    When I upload a file it will be saved in another account on content in the admin console. The integration is creating a new account between my account and the app integration.

    0
    Comment actions Permalink
  • Alex Novotny

    Great! For the client you instantiated, what parameters did you pass in? In that github repo you sent, there are several authentication type options. This probably explains why it is going to the application service account's content repository and not your own personal one. The client would need to be created with your users information. 

    Hope this helps!

     

    0
    Comment actions Permalink
  • Matheus Cruz

    This app will cover a lot of clients, to every user I authorize my app in the admin console and use user's interpriseId

    0
    Comment actions Permalink
  • Matheus Cruz

    I'm using this method to autheticate.

    var boxJWT = new BoxJWTAuth(
        new BoxConfig(
    _boxAppSettings.ClientID, _boxAppSettings.ClientSecret, enterpriseId,
    _boxAppSettings.AppAuth.PrivateKey, _boxAppSettings.AppAuth.Passphrase, _boxAppSettings.AppAuth.PublicKeyID
    )
    );
    var adminToken = boxJWT.AdminToken();

    _boxCliente = boxJWT.AdminClient(adminToken);
    0
    Comment actions Permalink
  • Alex Novotny

    Correct! The client you are making in the above code is using your JWT config information - this defaults to the service account (the account you are seeing content in). In order to place it in another user's account, you need to be making as-user calls. To do this with the .net sdk, you have to make a client using the credentials of the user you wish to make the API call as. Refer to this page. I believe there is sample code on the .net sdk github main page too. 

    0
    Comment actions Permalink

Please sign in to leave a comment.