Skip to main content

Hi,I'm Japanese.

I'm not good at English, but I want you to tell me this problem.

 

I want to upload files from log server to box using boxAPI in python at regular intervals.

 

First, I try this code using docs.

 #coding: UTF-8

from boxsdk import JWTAuth
from boxsdk import Client 

# JWT?????????????
sdk = JWTAuth(
client_id="XXXX",
client_secret="XXXX",
enterprise_id="XXXX",
jwt_key_id="XX,
rsa_private_key_file_sys_path="XXXX",
rsa_private_key_passphrase=str.encode("XXXX")
)

# ?????????????
client = Client(sdk)

# ????????????
file_path = '/box/upload/testfile20190204_1'
file_name = 'testfile20190204_1D'
folder_id = '0'

box_file = client.folder(folder_id).upload(file_path, file_name)

I can upload files related to the application.(test-boxapi)

box.png

 

but I want to upload box user's folder like this.

box2.png

 

I'd like some advice.

Thanks.

 



 When you use JWT authentication, you are authenticating as a special user related to your application called a Service Account .  This user has its own folders and files separate from any other user, including your own account.  Files uploaded by the Service Account do not automatically show up in the web application.


 


If you want the files to be uploaded into a specific account other than the Service Account, you will need to do two things:


  1. Make sure that your application has the ability to make calls as different users enabledScreen Shot 2019-02-06 at 3.40.47 PM.png

     




  2. Re-authorize your application in the Box Admin Console




  3. Make the upload API call with the user ID of the account you want to store the files in


     #coding: UTF-8

    from boxsdk import JWTAuth
    from boxsdk import Client

    # JWT?????????????
    sdk = JWTAuth(
    client_id="XXXX",
    client_secret="XXXX",
    enterprise_id="XXXX",
    jwt_key_id="XX,
    rsa_private_key_file_sys_path="XXXX",
    rsa_private_key_passphrase=str.encode("XXXX")
    )

    # ?????????????
    client = Client(sdk)

    # ????????????
    file_path = '/box/upload/testfile20190204_1'
    file_name = 'testfile20190204_1D'
    folder_id = '0'

    user_id = 'PUT_THE_USER_ID_HERE'
    box_file = client.as_user(user_id).folder(folder_id).upload(file_path, file_name)


I hope that helps!




 

Thanks!!

I Succeeded using 'As-User' 

 

 

 



Reply