Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 31: Uploading files to server with the File Upload API
February 7, 2015 by markpiller
Spread the love
There are several way to upload file content to the server:
  1. A traditional approach where a physical file from the client environment is uploaded using the API.
  2. Creating a remote file with content generated on the client side.
In this article I will review the first option – uploading a file with the API.
Once a file is uploaded, the File Service enables the following:
  • You can see the file in File Browser in Backendless console.
  • File can be downloaded via a URL assigned to it. The URL is composed as:
  • Application developer can assign permissions to control who (users or roles) can download or delete the file.
  • If git integration is enabled for the application, the file is also committed to the repository.

The example below demonstrates the API for file upload:

Asynchronous Call Example (Plain Java and Android):

Synchronous Sample (Plain Java only):

Suppose there is a input type=”file” control. The handleFileSelect function is attached as a handler to the control and is called when user selects a file for upload:

Asynchronous API sample:

Synchronous API sample:

Asynchronous Sample

Synchronous Sample

Asynchronous Sample

Synchronous Sample

Imagine that you have handler to handle upload file event:
So when you click on ‘Upload’, You add some objects type File to input type=”file” storage. You will use next handler to upload files to Backendless:

How to attach handleFileSelect to input=”file” control?

Synchronous API sample: 

Asynchronous API sample: :

When you run the code and the files are uploaded, you can see them in Backendless console. To do that:
  1. Login to console, select your app and click the Files icon.
  2. You will see the “myfiles” directory created by the code above. Click the directory name to see its contents.
  3. You should see two files as shown in the screenshot below.
    files saved with api - Feature 31: Uploading files to server with the File Upload API
  4. To see the contents of the file click the Edit file icon:
    file editing - Feature 31: Uploading files to server with the File Upload API

Enjoy!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+