Command Line to your Box


[php]session_start();
include(‘lib/Box_Rest_Client.php’);
$api_key = ‘kblpjd99g58ipaerbcst6yq35sl802cn’;
$box_net = new Box_Rest_Client($api_key);

if(!array_key_exists(‘auth’,$_SESSION) || empty($_SESSION[‘auth’])) {
$_SESSION[‘auth’] = $box_net->authenticate();
}
else {
$box_net->auth_token = $_SESSION[‘auth’];
}
$acctinfo = $box_net->get(‘get_account_info’, array(
‘api_key’ => $api_key,
‘auth_token’ => $_SESSION[‘auth’]
));

if ($acctinfo[‘status’] == ‘get_account_info_ok’) {
$_SESSION[‘space_amount’] = $acctinfo[‘user’][‘space_amount’];
$_SESSION[‘space_used’] = $acctinfo[‘user’][‘space_used’];
$_SESSION[‘max_upload_size’] = $acctinfo[‘user’][‘max_upload_size’];
}
[/php]Here you go, your Box auth_token is [php]echo $_SESSION[‘auth’];[/php].

You can now use it to upload files to your Box account from the command line. Let’s say you want to upload a file named text.txt to the root folder of your Box account. Just do this:

curl -F file=@test.txt 'https://upload.box.net/api/1.0/upload/[php]echo $_SESSION['auth'];[/php]/0'

If you want to upload that file to another Box folder you’ve already created, just navigate in your browser to that folder, and find the folder ID in the URL. For example, in this URL (https://www.box.com/files#/files/0/f/123456789/backups) the folder ID is 123456789. Once you’ve got the folder ID, you can upload to that folder by putting the folder ID at the end of the upload URL, like this:

curl -F file=@test.txt 'https://upload.box.net/api/1.0/upload/[php]echo $_SESSION['auth'];[/php]/123456789'

NOTES:

[php]
echo “You are currently using “, number_format($_SESSION[‘space_used’]/1024/1024), “M of the “, number_format($_SESSION[‘space_amount’]/1024/1024), “M in your Box account, and the largest file you can upload is “, number_format($_SESSION[‘max_upload_size’]/1024/1024), “M.”;
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *