File Upload

Top  Previous  Next

The file upload operation delivers and saves a local file in the remote Backendless file storage. The return value of the operation is the file URL which has the following structure:

https://api.backendless.com/<application id>/<version name>/files/<path>/<file name>

where:

<application id>- ID of the application which can be obtained from the Manage > App Settings screen of the Backendless Console
<version name>- application's version name
<path>- directory path where the file is saved
<file name>- name of the file

The URL assigned to a file and returned as a result of the upload operation accounts for any security permissions assigned to the file (or the folder it is located in).

Backendless Console includes a file browser with the management functions to upload files, create or delete directories and files. The file  browser is available in the Files section of the console:

backendless-file-browser.zoom50

File browser also provides a way to see the contents of the files. Every file is a link which opens the file. The URL of files in file browser is not the same as the URL returned by the file upload operation. The reason file browser uses a different URL is to let the application developer see the file contents without any application security constraints. The only constraint applied to the URLs available in file browser is the application developer must be logged to the console.

Method:

POST

URL:

https://api.backendless.com/<version>/files/<path>/<filename>?overwrite=true

where:

<version>- name of the application's version. Application versions can be managed using Backendless Console. Login to the console, select an application, click Manage, then Versioning. Backendless automatically creates version "v1" for any new application.
<path>        - directory path in the Backendless file storage where the file should be stored. If the path does not exist, Backendless File Service creates the directory structure.
<filename>        - name of the file the upload is saved as.
overwrite- defines whether a newly saved file overwrites the existing file. If the argument value is true, the new file overwrites the existing one. Otherwise, if the value is false or the overwrite parameter is not present, and another file with the same name already exists, the server returns an error.

Request Headers:

application-id: app-id-value
secret-key: secret-key-value
Content-Type: application/json
application-type: REST
user-token: user token value

where:

app-id-value- the ID of your application generated upon its creation. You can find this header in the Manage > App Settings section of the Backendless Console. This header is mandatory. Please refer to the Setup section for information on how to obtain the values for the header.
secret-key-value - the key of your application generated upon its creation. You can find this header in the Manage > App Settings section of the Backendless Console. This header is mandatory. Please refer to the Setup section for information on how to obtain the values for the header.
Content-Type - a static value, should be set to application/json. This header is mandatory.
application-type- a static value, should be set to REST. This header is mandatory.
user token value- a value identifying currently logged in user (if any). The value is received in the response for the login API.  The token uniquely identifies the user and the roles associated with him. It is used by Backendless to establish user's identity for all operations where the token is present. It is necessary in order to determine permissions applicable to the user and the roles associated with the account. This header is optional.

Sample Request Body:

File contents

Sample Response Body:

{
 "fileURL" : file URL which should be used to download the file
}

Example:

curl
-H application-id:application-id-value-from-console
-H secret-key:secret-key-value-from-console
-H Content-Type:"multipart/form-data"
-H application-type:REST
--form upload=@test.txt
-X POST
-v http://api.backendless.com/v1/files/txtfiles/test.txt

 


Please let us know how we can improve the documentation by leaving a comment. All technical questions should be posted to the Backendless Support forum. We do not respond to the technical questions on the documentation pages.: