File Service (12 posts)

Since Backendless does not have native APIs to download files, today we’ll talk about how to implement this function in your Android application. In order to do that, we’ll need to combine Backendless file listing API and There are several alternatives to this approach, but the selected one requires less code to write and has a well-thought structure.

Once a developer uploads files to the Backendless Files system, each file gets a public URL which can either be obtained using the Backendless Console or calculated using the following URL scheme:

publicURL 1024x472 - How to download a file stored in Backendless with your Android appThis public URI is the full path to the file in your Backendless file system. Directory listing API returns a list of the  FileInfo objects representing the files located in the directory, where each element in the collection contains the following properties:

  • name  – the name of the file or directory without any path information
  • public URL  – absolute URL of the file or directory
  • URL  – relative URL of the file or directory starting from the root of the file storage
  • created on  – a timestamp indicating when the file or directory was created

In this guide, we’ll be dealing with listing and downloading all the files with the  .html  extension in the /web  folder located in the root directory of your Backendless file system.

As for the Android app itself, we’ll need to:

  1. Define the  INTERNET and WRITE_EXTERNAL_STORAGE  permissions in Android manifest:
  2. Create a method to list all files in the directory:

    In this code sample, allFiles is a variable, which stores the results of the listing operation, and filesList is a TextView class where we show all the existing files.

    When the listing process is finished, we can start the download.

  3. Create a method which gets the public URIs of each file in a directory and will download these files in series:

    That’s all we need to make it work on Android devices with SDK < 23. On devices with SDK 23+, we’ll have application users to grant the permission to use their device storage. A method to check the device SDK and to ask for permission (if necessary) may look like this (in our code sample it is called before the download starts in Step 3):

We need to call this method in download method of your download activity  class. The result of the user choice should be handled in a separate callback, the same callback the download process should be restored:

Where downloadFiles is a button to start the download.

 The whole test app interface will look like this:

mainActivity - How to download a file stored in Backendless with your Android app

Selection 154 - How to download a file stored in Backendless with your Android app

Once you click the ALLOW button, the download process will be started.

Selection 155 - How to download a file stored in Backendless with your Android app

That’s it! The archive with this application can be found here:

Don’t forget to add your Backendless AppId and Android API key in the  Defaults class.

Thanks for reading this post, hope you like it! 

The release of Backendless 4.5.0 introduces support for file search in Backendless console. We already had search API in our SDKs (Android, iOS, JS, REST) and based on the feedback from the customers added search support in console. Here’s what you can do now in console:

Basic search

Type in a partial or full name of the file. Backendless displays a list of search results with the corresponding path. Clicking the file name in the “Name” column opens the file in a new browser tab. If the search result is a directory, clicking it will open the search result screen for that directory. There is also the “Search in subdirectories” checkbox, the meaning of which is quite self-explanatory:

basicsearch withsubs - File Search in Backendless Console

Search with a glob pattern

The search query can use the glob syntax to express patterns for file and directory names:

search with glob - File Search in Backendless Console

Search in Create a File Relation

Your database schema may include columns with the FILE REFERENCE type. Here’s an example of such data table column:

create file ref - File Search in Backendless Console

When you establish a relation with a specific file, you work with the popup shown below. As you can see, it now has an ability to perform file search:

create file ref popup - File Search in Backendless Console


Previously I wrote how to upload files to the Backendless Hosting system. Once a file is uploaded, it gets a public URL which can either be obtained using Backendless console or calculated using the following template:

Alternatively, when a file is uploaded, the API call returns the URL of the uploaded file. The sample code below demonstrates how to download the file. The code prints out the contents of the file to system console, but it can be easily modified to store it in the local file system, or transfer elsewhere over the network, etc:
Continue reading

Any file in the Backendless File storage is also accessible through a public URL. This functionality can be restricted by changing security settings. Public file URL can be built using the following format:

where <application id>   <path> and  <filename> should be replaced with the specific values. Another way to obtain file’s public URL is by using Backendless console:
Continue reading

Directories in the file storage can be created implicitly as a result of uploading files using the File Service API. Alternatively, a directory can be created using Backendless console. To do that:

  1. Login to Backendless console, select your app and click he Files icon.
  2. Navigate to a directory where a new directory should be created (or just stay in the root one).
  3. Click the New Folder button.
  4. Enter the name of the directory in the popup and click the Save button.
  5. The directory is created and can be used right away in console as well as the APIs.

new directory button - Feature 67: Creating directories in Backendless File Storage

Backendless is not just a mobile backend – it also provides hosting and runtime support for browser-based applications. Indeed, we offer a fully-featured SDK for JavaScript apps. Unless you host your Backendless-powered app in our Hosting system, you will be running into cross-origin domain requests. This occurs when an application is loaded into a browser from one host, but then it makes a request (XHR, socket, etc) to another host. In the case of Backendless, the second host would be the backend platform we provide.

Continue reading

Previously I described how to upload files to Backendless file storage using File Service API. In addition to the file upload API, Backendless console supports online (built into the console) text editor. The editor lets you create new files with just a click of a button:

  1. Login to Backendless console, select your app and click the Files icon.
  2. Browse to a directory where the file should be created and click the New File button from the toolbar.
  3. Enter the name of the file and select a syntax highlighter.
  4. As you edit the file, the editor can also highlight syntax errors for most document types:creating new files in backendless - Feature 46: Creating new files in file storage using console's online text editor
  5. Click Save to save the file. It immediately becomes available for download.

In one of my previous posts I wrote about Backendless File Browser – an online management for your files and directories. One of the features built into File Browser is the ZIP Directory feature. The feature does exactly what it sounds like it would do – creating a zip file for a directory and its contents. At any level of your directory hierarchy, you can click the ZIP Directory button and Backendless creates a zip file with the name of the directory. The file is created at the same level in the hierarchy as the directory which is being zipped.
zip directory button - Feature 41: Compress any directory in your Backendless file storage using console

Backendless file storage includes a very powerful (and quite convenient) integration with git. There are many features which come with that integration and I will be describing them in detail in future posts. Here’s a brief list of what you can do with it:

  • Work with your file storage as with a fully-functional GIT repository.
  • Upload files to Backendless via API or with the Backendless Console and they are automatically added to the repository.
  • Add/commit files via GIT and they are automatically copied to the “browseable” file storage. These files become accessible via Backendless download API, and the web server function.
    Continue reading

Backendless File storage can be used to host web applications. The file storage includes a special directory – “/web” which is used to host web application content. Since the default URLs for files in your file storage are rather long and use the domain, it may be desirable to map a custom domain name to your Backendless backend and specifically the file storage. Note that at the time of writing of this post, this feature is available for the applications in the Backendless Plus pricing plan, but that may change in the future.

Continue reading
Find us in facebook