Welcome!

APIs for the Internet of Things

Max Katz

Subscribe to Max Katz: eMailAlertsEmail Alerts
Get Max Katz via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Blog Feed Post

How to Upload Files From a Mobile App to a Cloud Database

cloud_upload1

Mobile developers often face the need to upload binary files, such as images, to the database. For example, this could happen in an app like Instagram, where a user takes photos with the device’s camera and then publishes it to their followers. Of course, all the data — including images — should be stored in the database, so the user can sign in from any device and see his or or her feed.

Another possible case for uploading images is sending an MMS (multimedia message) from your app, which can be done via the Twilio API. Twilio accepts a direct URL to an image. A user takes a picture with the device and uploads it to the Appery.io database. Then, a direct image URL is passed to the Twilio API.

In Appery.io, there are three ways to upload files to the database :

  • Via Web API (this approach uses only the browser API).
  • Via Cordova file-transfer.
  • Via the Input component and JavaScript helper (It’s also possible to upload multiple files via the Input component, see this tutorial for more).

We’ve created a plug-in for the first two of these, and, with it, you can quickly implement file uploading in your mobile Appery.io app. It consists of two pages – cordovaupload and webupload. The cordovaupload uses the Cordova file-transfer plug-in. To make it work, the app has to run on the device or via the Appery.io Tester app.

The webupload page uses the browser FormData API to upload a file. This approach can be used to test the app in the browser, which is faster than on the device without having to take a picture each time. The Web API can be also used to upload images taken via the camera on the device.

A quick note about configuring the plugin: the Appery.io database requires a sessionToken for uploading files to the database. To make the plugin simpler to use, it uses the Master Key. So, to configure this plugin, you should provide the ID of the database that will be used to store files and the Master Key instead of sessionToken.

However, please keep in mind that for security reasons, we recommend you use sessionToken instead of Master Key. You can learn how to implement user authentication and registration with Appery.io here.

This plug-in is configured out-of-the-box to work with the Appery.io database, but it can be modified to work with any other API provider that allows file upload. You will need to change the upload REST API and update any parameters.

As usual, we’ve prepared a detailed tutorial for this plug-in, which you can find here.

If you have any problems with this plug-in or with file uploading in Appery.io, contact our support and they will help you right away.

Originally posted on the Appery.io blog


Read the original blog entry...

More Stories By Max Katz

Max Katz heads Developer Relations for Appery.io, a cloud-based mobile app platform. He loves trying out new and cool REST APIs in mobile apps. Max is the author of two books “Practical RichFaces” (Apress 2008, 2011), DZone MVB (Most Valuable Blogger), and is a frequent speaker at developer conferences. You can find out what Max is up to on his blog: http://maxkatz.org and Twitter: @maxkatz.