Git Product home page Git Product logo

cordova-filestorage's Introduction

Cordova FileStorage Plugin

This plugin offers a wrapper around the handling with content and file URIs. It offers a functions for users to select a file on the device or dropbox and the read from it and write to it without the need to process the URIs used by android to describe files.

Install

Install with Cordova CLI

$ cordova plugin add https://github.com/DFranzen/cordova-FileStorage.git

JavaScript API

The API is accessible via the global object fileStorage. After the deviceready event has been fired, the functions can be accessed as the fields of this object:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady () {
    console.log(fileStorage);
}

open

After this, a storage URI can be obtained from the user by calling fileStorage.open(success, error);

It displays a choice to the user to open a file from android's standard file choosing dialog or the Dropbox app. After the user chooses, one of the callback functions is called with the result

function success (uri) {
    console.log(uri);
}

function error (errorMsg) {
    console.log(errorMsg);
}

The uri returned to the success function is a string representation of either a file:// or content:// describing a local or remote content. This string has to be passed to the other API functions to describe the chosen file.

readFromUri To read the content of a file with the obtained uri call:

fileStorage.readFromUri(success, error, uri)

One of the callback functions will be called with the result:

function success (data) {
    console.log(data);
}

function error (errorMsg) {
    console.log(errorMsg);
}

writeToUri To overwrite the content of a file with the obtained uri call:

fileStorage.writeToUri(success, error, uri, data)

The parameter data is a string which will be the content of the file described by uri on success. One of the callback functions will be called with the result:

function success () {
    console.log("written");
}

function error (errorMsg) {
    console.log(errorMsg);
}

appendToUri To append a string to the content of a file with the obtained uri call:

fileStorage.appendToUri(success, error, uri, data)

One of the callback functions will be called with the result:

function success () {
    console.log("written");
}

function error (errorMsg) {
    console.log(errorMsg);
}

File Handling

If the runtime permission to read / write the file-system is not currently held by the app, all functions prompt the user to grant the permission and call the error callback with an appropriate error message. The API does not try to re-execute the operation after the permission has been granted.

All files which are read from and written to are opened if necessary and closed after the operation. No further handling is necessary.

Supported Platforms:

Android

Tested on

Cordova: 6.4.0 PhoneGap: 6.4.2

Android: 6.0.1

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.