-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(preview-any-file): add new plugin to preview the … (#3156)
* feat(cordova-plugin-preview-any-file): add new plugin to preview the files in both ios and android * fix lint error * add missing descriptions * add the reop link
- Loading branch information
1 parent
d9ded4d
commit fcec2d1
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; | ||
/** | ||
* @name PreviewAnyFile | ||
* @description | ||
* Whatever the file is PDF document, Word document, Excel, office document,zip archive file, image, text, html or anything else, you can perform a preview by this cordova Plugin to preview any file in native mode by providing the local or external URL. | ||
* | ||
* Requires Cordova plugin: `cordova-plugin-preview-any-file`. For more info, please see the [previewAnyFile plugin docs](https://github.com/mostafa-mansour1/previewAnyFile). | ||
* | ||
* @usage | ||
* ```typescript | ||
* import { PreviewAnyFile } from '@ionic-native/preview-any-file'; | ||
* | ||
* | ||
* constructor(private previewAnyFile: PreviewAnyFile) { } | ||
* | ||
* ... | ||
* | ||
* | ||
* this.previewAnyFile.preview('file://filepath.ext') | ||
* .then((res: any) => console.log(res)) | ||
* .catch((error: any) => console.error(error)); | ||
* | ||
* ``` | ||
*/ | ||
@Plugin({ | ||
pluginName: 'PreviewAnyFile', | ||
plugin: 'cordova-plugin-preview-any-file', // npm package name, example: cordova-plugin-camera | ||
pluginRef: 'PreviewAnyFile', // the variable reference to call the plugin, example: navigator.geolocation | ||
repo: 'https://github.com/mostafa-mansour1/previewAnyFile', // the github repository URL for the plugin | ||
install: '', // OPTIONAL install command, in case the plugin requires variables | ||
installVariables: [], // OPTIONAL the plugin requires variables | ||
platforms: ['Android', 'iOS'] // Array of platforms supported, example: ['Android', 'iOS'] | ||
}) | ||
@Injectable() | ||
export class PreviewAnyFile extends IonicNativePlugin { | ||
/** | ||
* this function return SUCCESS in success callback if the file successfully opened, if the content is base64 you have to write it into file by cordova-plugin-file | ||
* @param url {string} full absolute URL for the file, if the path is content:// you need to resolve the native url, if the path is https:// it may not work in android | ||
* @return {Promise<any>} Returns a promise that resolves if the file opened reject if not; | ||
*/ | ||
@Cordova() | ||
preview(url: string): Promise<string> { | ||
return; | ||
} | ||
} |