Giter VIP home page Giter VIP logo

cordova-background-upload's Introduction

Background Upload Plugin for Cordova

This plugin provides a file upload functionality via javascript without necessarily using the browser platform of cordova. On the web it will use SuperAgent to post the files. Since it is done via Ajax, make sure your server supports CORS (cross origin requests).

The following browsers are supported:

  • Latest Firefox, Chrome, Safari
  • IE10 through latest

Note: Background uploads are not supported on the web

When in a mobile environment, it will rely on the cordova-plugin-background-upload to allow for background uploads. If the plugin is not installed,it will fallback to superagent upload.

Installation

npm install --save cordova-background-upload

For mobile uploads:

cordova plugin add cordova-plugin-file --save
cordova plugin add cordova-plugin-background-upload --save

For android, you need to add the permission library also:

cordova plugin add cordova-plugin-android-permissions --save

Sample usage

 import { BackgroundUpload } from 'cordova-background-upload';

 var uploader = new BackgroundUpload().init();

 uploader.on('success', function(upload) {
     console.log("upload: " + upload.id + " has been completed successfully");
     console.log(upload.serverResponse);

 });

 uploader.on('progress', function(upload) {
     console.log("uploading: " + upload.id + " progress: " + upload.progress + "%");

 });

 uploader.on('error', function(uploadException) {
     if (uploadException.id) {
         console.log("upload: " + uploadException.id + " has failed");
     } else {
         console.error("uploader caught an error: " + uploadException.error);
     }
 });

Adding an upload is done via the upload method. In case the plugin was not able to enqueue the upload, an exception will be thrown in the error event listener.

 var payload = {
     "id": "sd4ed",
     "file": fileObject, //the file object obtained from an input type='file'
     "serverUrl": "http://requestb.in/14cizzj1",
     "headers": {
         "api_key": "asdasdwere123sad"
     },
     "parameters": {
         "signature": "mysign",
         "timestamp": 112321321
     }
 };

uploader.upload(options);

Configuration

  • id: a unique identifier to track the uploads (String)
  • filePath: the absolute path for the file to upload (applicable only on mobile platforms), if you are using an html input type file, write the file to disk, then use its path
  • file: the file object obtained from an input type='file' (used only on browser)
  • serverUrl: remote server url
  • headers: custom http headers
  • parameters: custom parameters for multipart data

Credits

cordova-background-upload is brought to you by Spoon Consulting.

cordova-background-upload's People

Contributors

l0stpenguin avatar ombr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-background-upload's Issues

Uploading image Multiple times

As im trying to upload multiple images by this plugin but after firing upload event it shows in console that it is failed(not all time) to upload but simultaneously it upload it to server but after that exact problem starts, the file uploaded to the server many times. uploader upload same file 3 to 4 times.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.