Socket
Book a DemoInstallSign in
Socket

cordova-plugin-document-contract

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-plugin-document-contract

Cordova plugin to interact with an Android Document Provider.

0.4.1
latest
Source
npmnpm
Version published
Weekly downloads
18
-41.94%
Maintainers
1
Weekly downloads
 
Created
Source

cordova-plugin-document-contract

Android document / media provider plugin for Cordova

Installation

Install through the Cordova plugin repository:

cordova plugin add cordova-plugin-document-contract

Install directly from github:

cordova plugin add https://github.com/danjarvis/cordova-plugin-document-contract.git

Methods

The plugin exposes two functions for working with a document/media provider.

getContract({
    uri: 'content://com.foo.bar/xyz',  // content URI (required)
    columns: ['_display_name']         // projection of columns (optional)
  },
  success,                             // success callback
  error);                              // error callback

Resolves a content URI and retrieves a contract object.

An object of key/value pairs will get passed to the success callback (keys will becolumns that returned a value).

If columns is not specified, the query will return all available columns. This is not recommended as it is inefficient.

Documentation for columns of interest:

createFile({
    uri: 'content://com.foo.bar/xyz'	// content URI (required)
    fileName: 'file.pdf'                // name of output file (required)
  },
  success,                              // success callback
  error);                               // error callback

Resolves a content URI, retrieves corresponding file data and writes it to a file in the application's data directory (cordova.file.dataDirectory).

Usage

For the below examples, assume that

  • contentUri is valid Content URI (e.g. coming from a Google Drive Send Intent).
  • The Cordova File Plugin plugin is installed.

Get a full contract:

window.plugins.DocumentContract.getContract({
    uri: contentUri
  },
  function(contract) {
    console.dir(contract);
    // Outputs
    // {
    //   '_display_name': 'SampleFile.pdf',
    //   'document_id': 'foo123',
    //   'last_modified': '/SomeDate/',
    //   'mime_type': 'application/pdf',
    //   'nth key': 'nth value'
    // }
  },
  function(error) {
    console.log('Error getting contract: ' + error);
  }
);

Get a specific contract:

window.plugins.DocumentContract.getContract({
    uri: contentUri,
    columns: [
      '_display_name', 'mime_type', '_size'
    ]
  },
  function(contract) {
    console.dir(contract);
    // Outputs
    // {
    //   '_display_name': 'SampleFile.pdf',
    //   '_size': '5242880',
    //   'mime_type': 'application/pdf'
    // }
  },
  function(error) {
    console.log('Error getting contract: ' + error);
  }
);

Get file name and create file:

window.plugins.DocumentContract.getContract({
    uri: contentUri,
      columns: [
      '_display_name'
    ]
  },
  function(contract) {
    window.plugins.DocumentContract.createFile({
        uri: contentUri,
        fileName: contract['_display_name'] || 'unknown'
      },
      function(fileName) {
        resolveLocalFileSystemURL(
          cordova.file.dataDirectory + fileName,
          function(fileEntry) {
            // Do something with FileEntry
          },
          function(error) {
            console.log('Error resolving file: ' + error);
          }
        );
      },
      function(error) {
        console.log('Error creating file: ' + error);
      }
    );
  },
  function(error) {
    console.log('Error getting contract: ' + error);
  }
);

License

© Dan Jarvis 2015, MIT

Keywords

ecosystem:cordova

FAQs

Package last updated on 06 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.