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.
$ cordova plugin add cordova-plugin-filepath
- Android
Once installed the plugin defines the window.FilePath
object. It offers the following functions:
Allows to resolve a native file path from a content URI.
Example:
window.FilePath.resolveNativePath("content://com.example.app/cache/1.pdf", successCallback, errorCallback);Returns the
file://
file path.Returns the following object:
{ code: <integer>, message: <string> }Possible error codes are:
-1
- describes an invalid action0
- path could not be resolved1
- the native path links to a cloud file (e.g: from Google Drive app)
Retrieves the filename and data from the
InputStream
supplied by theContentProvider
of the passed URI. The result is supplied inside aPromise
, which is resolved with theObject
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); } })();
Apache (see LICENSE.md)