ApiFunction_Upload and Download

Page history last edited by jeremy@... 1 wk ago


 

download

 

To download a file, You can make a GET request of the form:

 

https://www.box.net/api/1.0/download/<auth_token>/<file_id>

 

This works just like a direct download link.  However, you will not want this link to be displayed to anyone except for the applied user, as the auth_token here can be used in other API calls.

 

A sample download request would look like this:

 

https://www.box.net/api/1.0/download/0ef4e2b1be630554ffa4044c054b1954/542666

 

upload, overwrite, new_copy

 

To upload a file, you can send an HTTP POST request to:

 

https://upload.box.net/api/1.0/upload/<auth token>/<folder id>

Note: Uploading a file to this URL will overwrite the file if a file by the same name already exists.  You may want to programmatically check for the existence of a file of the same name, in the folder to which you are performing the upload.

 

If you wish to explicitly overwrite a particular file (useful especially for OpenBox Actions), send the request to:

 

https://upload.box.net/api/1.0/overwrite/<auth token>/<file_id>

Note: You do not have to construct this URL manually if you are creating an OpenBox Action. The platform an  overwrite_url as a Callback Parameter that you can receive automatically.

 

If you wish to make a new copy of a file that exists (and take the filename of that file and append "(<copy_number>)" to it):

 

https://upload.box.net/api/1.0/new_copy/<auth token>/<file id>

Note: You do not have to construct this URL manually if you are creating an OpenBox Action. The platform an  new_copy_url as a Callback Parameter that you can receive automatically.

 

Input parameters:

 

Aside from using the auth_token and folder_id or file_id in the URL itself, you can provide the following parameters for your upload request.

 

Name Type Description
file content The file itself (multi-part form upload).   You can provide multiple files in an upload request.
share long (boolean) Whether the file should be shareable on Box.  This is an optional parameter.
message string An message to be included in a notification email, if the file will be shared with others.
emails ArrayOfString An array of emails to which to notify users about the newly shared file.

 

Output parameters:

 

Name Type Description
status string

If the operation was successful, the status parameter will be 'upload_ok'.

If the operation was not successful, the status field can be:

  • 'wrong auth token' - The user is not logged into your application.  Your authentication_token is not valid.
  • 'application_restricted'- You provided an invalid api_key, or the api_key is restricted from calling this function.
  • 'upload_some_files_failed' - Some of the files were not successfully uploaded.
  • 'not_enough_free_space' - There is not enough space in this user's account to accommodate the new files.
  • 'filesize_limit_exceeded' - A file is too large to be uploaded to a user's account (Lite users have a 25 MB upload limit per file, premium users have a 1 GB limit per file)
  • 'access_denied' - The user does not have uploading privileges for that particular folder.
Files Base64encoded A list of the files that were uploaded.

 

 

 

Sample Upload Request

 

As a simple example to upload to Box via the API , consider creating an HTML form. An upload might look like the following:

 

<form action="https://upload.box.net/api/1.0/upload/0ef4e2b1be630554ffa4044c054b1954/756"
enctype="multipart/form-data" method="POST">
<input type="file" name="new_file1" />
<input type="file" name="new_file2" />
<input type="text" name="share" value="1" />
<input type="text" name="message" value="Hello" />
<input type="text" name="emails[]" value="test@domain.com" />
<input type="text" name="emails[]" value="test1@domain.com" />
<input type="submit" name="upload_files" value="Upload File" />
</form>

 

Response format

 

<?xml version='1.0' encoding='UTF-8' ?>
<response>
<status>upload_ok</status>
<files>
<file file_name="read_me.txt" id="5996" folder_id="756" shared="0" public_name="" />
<file file_name="Rally.avi" error="filesize_limit_exceeded" />
</files>
</response>

 


 

Need additional assistance? Please feel free to Contact us