Welcome to the new Box Support website. Check out all the details here on what’s changed.

[API]Upload files using API in python

Answered
New post

Comments

2 comments

  • mwiller

     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!

    0
    Comment actions Permalink
  • IMAKOU

     

    Thanks!!

    I Succeeded using 'As-User' 

     

     

     

    -1
    Comment actions Permalink

Please sign in to leave a comment.