Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Uploading a file on a remote server


Sometimes, working with only the local system for mobile applications is not enough. There are use cases for the requirement to interact with a remote server, for example, to share a file.

How to do it...

In this recipe, we will build an application that allows the user to take a photograph and upload it on a remote server:

  1. Firstly, create a new PhoneGap project named upload by running the following line:

    phonegap create upload com.myapp.upload upload
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:

    cordova platform add ios
    cordova platform add android
    
  3. Add the file, camera, and file-transfer plugins by running these lines of code:

    phonegap plugin add org.apache.cordova.file
    phonegap plugin add org.apache.cordova.camera
    phonegap plugin add org.apache.cordova.file-transfer
    
  4. We're going to use the XUI JavaScript library to easily access the DOM elements, so we'll include the reference to the file within the head tag.

  5. Open www/index.html....