Giter VIP home page Giter VIP logo

cordova-plugin-filepath's Introduction

cordova-plugin-filepath

This plugin allows you to resolve the native filesystem path for Android content URIs and is based on code in the aFileChooser library. Alternatively, this plugin allows to get the contents of an InputStream associated to a Content URI. This is especially helpful, if a native path is not available.

Original inspiration from StackOverflow.

Installation

$ cordova plugin add cordova-plugin-filepath

Supported Platforms

  • Android

Usage

Once installed the plugin defines the window.FilePath object. It offers the following functions:

resolveNativePath

Allows to resolve a native file path from a content URI.

Example:

window.FilePath.resolveNativePath("content://com.example.app/cache/1.pdf", successCallback, errorCallback);
successCallback

Returns the file:// file path.

errorCallback

Returns the following object:

{ code: <integer>, message: <string> }

Possible error codes are:

  • -1 - describes an invalid action
  • 0 - path could not be resolved
  • 1 - the native path links to a cloud file (e.g: from Google Drive app)

getArrayBufferFromContentUri

Retrieves the filename and data from the InputStream supplied by the ContentProvider of the passed URI. The result is supplied inside a Promise, which is resolved with the Object or rejected with an error object.

Example:

(async () => {
  try {
       let result = await window.FilePath.getArrayBufferFromContentUri("content://com.example.app/cache/1.pdf");
       // result = {filename: string, content: array<number>}        
       // Use the result inside your code     
  } catch (error){
       // Example error: {code: 0, message: "No content provider: null"}
       console.warn(error);
  }
})();

LICENSE

Apache (see LICENSE.md)

cordova-plugin-filepath's People

Contributors

chrizc avatar hiddentao avatar kukukk avatar libinvarghese avatar mohammadwaleed avatar nmatpt avatar olaferlandsen avatar

Watchers

 avatar  avatar

Forkers

spideroak

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.