新しいBoxサポートサイトへようこそ。 変更点の詳細はこちらをご確認ください .

Upload files from Linux machine using command-line

新規投稿

コメント

2件のコメント

  • Rui Barbosa

    Hi Andrew,

    Have you tried the box-cli?

    For a remote linux box you need to use JWT authentication, take a look here.

    Walkthrough:

    ❯ box -v
    @box/cli/3.7.0 linux-x64 node-v14.21.2

    Get your config.json from creating a JWT app.  (save it on the remote server, be conscious of security)

    Configure your box-cli:

    ❯ box configure:environments:add -n your-app-name ./.config.json
    Successfully added CLI environment "your-app-name"

    Switch to the configuration:

    ❯ box configure:environments:set-current
    ? Which environment?
      uie-sample
    ❯ your-app

    Check connection and user context:

    ❯ box users:get --fields=id,name
    Type: user
    ID: '20344589936'
    Name: UI-Elements-Sample

    I have create a "Bulk Upload" folder in the root, so lets get that folder id:

    ❯ box folders:items 0 --csv
    type,id,sequence_id,etag,name
    folder,163422716106,0,0,Box UI Elements Demo
    folder,189803765719,2,2,ClassificationService
    folder,177388203339,0,0,100k
    folder,172599089223,0,0,Bookings
    folder,172611202270,0,0,My Signed Documents
    folder,170845975022,1,1,Waivers
    folder,176837925976,0,0,Webhook

    As you can see it is not there... This is because I created the folder on my person user (Rui) and the CLI is using the service account associated with the app and the JWT.

    So we need to use my person user.

    To get a list of users do:

    ❯ box users --fields=id,name --csv
    type,id,name
    user,18662105676,Administrator
    user,18662356345,Administrator
    user,18661971368,Administrator
    user,22240548078,Investment User
    user,22240405099,Wealth User
    user,22240545678,Wholesale User
    user,18622116055,Rui Barbosa

    So if I wanted my JWT app to impersonate me I would use my id on the --as-user

    ❯ box users:get --as-user=18622116055 --fields=id,name --csv
    type,id,name
    user,18622116055,Rui Barbosa

    And now I can list the folders of Rui:

    ❯ box folders:items 0 --csv --as-user=18622116055
    type,id,sequence_id,etag,name,file_version.type,file_version.id,file_version.sha1,sha1
    folder,163422716106,0,0,Box UI Elements Demo,,,,
    folder,172599089223,0,0,Bookings,,,,
    folder,172759373899,0,0,Barduino User Folder,,,,
    folder,191176042455,0,0,Bulk Upload,,,,
    folder,189803765719,2,2,ClassificationService,,,,

    Now we can use the destination folder if directly.

    I also have a folder with the files to upload:

    ❯ l files_to_upload
    total 0
    -rw-rw-r-- 1 lab lab 0 Jan 20 21:10 file_a.txt
    -rw-rw-r-- 1 lab lab 0 Jan 20 21:10 file_b.txt
    -rw-rw-r-- 1 lab lab 0 Jan 20 21:10 file_c.txt

    Now we need to upload the files to the folder, in my case: 191176042455

    We have several options depending if you are dealing with a large list of files and their location.

    To upload an entire folder:

    ❯ box folders:upload --parent-folder 191176042455 --as-user 18622116055 files_to_upload --csv --fields type,id,name
    type,id,name
    folder,191177421988,files_to_upload

    To upload a single file:

    ❯ box files:upload --parent-id 191176042455 --as-user 18622116055 files_to_upload/file_a.txt --csv --fields type,id,name
    type,id,name
    file,1119062117269,file_a.txt

    Of course you can play with bash or use a CSV as an input file with a list of paths.

    Let us know if this helped.

    The end result:

    Cheers

     

    0
    コメントアクション パーマリンク
  • Nikhil Ghadigaonkar

    I have uploaded the file and also got a success response from the command line. But can't view the uploaded file from the UI.
    If I upload using the developer token the file I can see in the UI. using the access token not

    0
    コメントアクション パーマリンク

サインインしてコメントを残してください。