diff --git a/src/plugins/camera-preview.ts b/src/plugins/camera-preview.ts index 492ecb4cf..27e17f507 100644 --- a/src/plugins/camera-preview.ts +++ b/src/plugins/camera-preview.ts @@ -33,13 +33,13 @@ export interface CameraPreviewSize { * @description * Showing camera preview in HTML * - * Requires {@link module:driftyco/ionic-native} and the Cordova plugin: `cordova-plugin-camera-preview`. For more info, please see the [Cordova Camera Preview Plugin Docs](https://github.com/westonganger/cordova-plugin-camera-preview). + * Requires {@link module:driftyco/ionic-native} and the Cordova plugin: `cordova-plugin-camera-preview`. For more info, please see the [Cordova Camera Preview Plugin Docs](https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview). * */ @Plugin({ plugin: 'cordova-plugin-camera-preview', pluginRef: 'cordova.plugins.camerapreview', - repo: 'https://github.com/westonganger/cordova-plugin-camera-preview', + repo: 'https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview', platforms: ['Android', 'iOS'] }) export class CameraPreview { @@ -104,10 +104,10 @@ export class CameraPreview { /** * Set the default mode for the Flash. */ - @Cordova({ - sync: true - }) - static setFlashMode(mode: number): void { }; + // @Cordova({ + // sync: true + // }) + // static setFlashMode(mode: number): void { }; /** * Set camera color effect. diff --git a/src/plugins/file.ts b/src/plugins/file.ts index cb0437030..1b18704af 100644 --- a/src/plugins/file.ts +++ b/src/plugins/file.ts @@ -363,9 +363,9 @@ export class File { try { var directory = path + file; - window.resolveLocalFileSystemURL(directory, function (fileSystem) { - if (fileSystem.isFile === true) { - resolveFn(fileSystem); + window.resolveLocalFileSystemURL(directory, function (fileEntry) { + if (fileEntry.isFile === true) { + resolveFn(fileEntry); } else { rejectFn({code: 13, message: 'input is not a file'}); } @@ -474,21 +474,17 @@ export class File { /** * Read a file as string. * - * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above - * @param {string} fileName Name of file to move + * @param {string} uri Base FileSystem. Please refer to the iOS and Android filesystems above * @return Returns a Promise that resolves or rejects with an error. */ - static readAsText(path: string, fileName: string): Promise { + static readAsText(file_uri: string): Promise { let resolveFn, rejectFn; let promise = new Promise((resolve, reject) => {resolveFn = resolve; rejectFn = reject; }); - if ((/^\//.test(fileName))) { - rejectFn('file-name cannot start with \/'); - } - try { - window.resolveLocalFileSystemURL(path, function (fileSystem) { - fileSystem.getFile(fileName, {create: false}, function (fileEntry) { + + window.resolveLocalFileSystemURL(file_uri, function (fileEntry) { + fileEntry.file(function (file) { var reader = new FileReader(); @@ -503,10 +499,52 @@ export class File { }; reader.readAsText(file); - }, function (error) { - error.message = File.cordovaFileError[error.code]; - rejectFn(error); - }); + + }, function (err) { + err.message = File.cordovaFileError[err.code]; + rejectFn(err); + }); + }, function (er) { + er.message = File.cordovaFileError[er.code]; + rejectFn(er); + }); + } catch (e) { + e.message = File.cordovaFileError[e.code]; + rejectFn(e); + } + + return promise; + } + + /** + * Read a file as string. + * + * @param {string} uri Base FileSystem. Please refer to the iOS and Android filesystems above + * @return Returns a Promise that resolves or rejects with an error. + */ + static readAsDataURL(file_uri: string): Promise { + let resolveFn, rejectFn; + let promise = new Promise((resolve, reject) => {resolveFn = resolve; rejectFn = reject; }); + + try { + + window.resolveLocalFileSystemURL(file_uri, function (fileEntry) { + + fileEntry.file(function (file) { + var reader = new FileReader(); + + reader.onloadend = function(e) { + if (this.result !== undefined && this.result !== null) { + resolveFn(this.result); + } else if (this.error !== undefined && this.error !== null) { + rejectFn(this.error); + } else { + rejectFn({code: null, message: 'READER_ONLOADEND_ERR'}); + } + }; + + reader.readAsDataURL(file); + }, function (err) { err.message = File.cordovaFileError[err.code]; rejectFn(err);