From 77480b64448d522a7cd4e781795340e8712fccab Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Thu, 30 Sep 2021 20:52:52 +0200 Subject: [PATCH 1/3] FILE_URI option for Cordova Add option for Cordova to select `destinationType` on Cordova to allow to switch to `FILE_URI` instead of the default `DATA_URL`. --- packages/mdg:camera/CHANGELOG.md | 4 ++++ packages/mdg:camera/README.md | 3 ++- packages/mdg:camera/package.js | 2 +- packages/mdg:camera/photo-cordova.js | 8 ++++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/mdg:camera/CHANGELOG.md b/packages/mdg:camera/CHANGELOG.md index 1d15b33..bff4892 100644 --- a/packages/mdg:camera/CHANGELOG.md +++ b/packages/mdg:camera/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v1.7.0, 2021- + +* Add option for Cordova to select `destinationType` on Cordova to allow to switch to `FILE_URI` instead of the default `DATA_URL`. + ## v1.6.0, 2021-09-02 * Updated versions from and less version, fix issue #123 diff --git a/packages/mdg:camera/README.md b/packages/mdg:camera/README.md index fc19b1e..647b367 100644 --- a/packages/mdg:camera/README.md +++ b/packages/mdg:camera/README.md @@ -15,8 +15,9 @@ Prompt the user to take a photo with their device and get the picture as a Data - `width` An integer that specifies the minimum width of the returned photo. - `height` An integer that specifies the minimum height of the returned photo. - `quality` A number from 0 to 100 specifying the desired quality of JPEG encoding. +- `destinationType` For Cordova ONLY. Pass in `URI` to get back file uri instead of base64 image (the default). -You can use other options from [Cordova Camera Options](https://cordova.apache.org/docs/en/10.x/reference/cordova-plugin-camera/#module_Camera) as they get passed on, with the exception of `destinationType`. +You can use other options from [Cordova Camera Options](https://cordova.apache.org/docs/en/10.x/reference/cordova-plugin-camera/#module_Camera) on Cordova as they get passed on. #### callback(error, data) diff --git a/packages/mdg:camera/package.js b/packages/mdg:camera/package.js index e778a90..c09b6b2 100644 --- a/packages/mdg:camera/package.js +++ b/packages/mdg:camera/package.js @@ -1,7 +1,7 @@ Package.describe({ name: "mdg:camera", summary: "Photos with one function call on desktop and mobile.", - version: "1.6.0", + version: "1.7.0", git: "https://github.com/meteor/mobile-packages" }); diff --git a/packages/mdg:camera/photo-cordova.js b/packages/mdg:camera/photo-cordova.js index dc9a34b..3e78c79 100644 --- a/packages/mdg:camera/photo-cordova.js +++ b/packages/mdg:camera/photo-cordova.js @@ -6,7 +6,11 @@ MeteorCamera.getPicture = function (options, callback) { } var success = function (data) { - callback(null, "data:image/jpeg;base64," + data); + if (options.destinationType === 'URI') { + callback(null, data); + } else { + callback(null, "data:image/jpeg;base64," + data); + } }; var failure = function (error) { @@ -18,7 +22,7 @@ MeteorCamera.getPicture = function (options, callback) { quality: options.quality || 49, targetWidth: options.width || 640, targetHeight: options.height || 480, - destinationType: Camera.DestinationType.DATA_URL + destinationType: options.destinationType === 'URI' ? Camera.DestinationType.FILE_URI : Camera.DestinationType.DATA_URL }) ); }; From d9569fed1db92baae21d89cba315e29117040062 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 15 Oct 2021 11:21:32 +0200 Subject: [PATCH 2/3] Apply destinationType to simple photo example & extend readme --- examples/simple-photo/client/main.js | 9 ++++++++- examples/simple-photo/package.json | 2 +- packages/mdg:camera/CHANGELOG.md | 2 +- packages/mdg:camera/README.md | 2 +- packages/mdg:camera/photo-cordova.js | 7 +++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/simple-photo/client/main.js b/examples/simple-photo/client/main.js index beb56b7..3d81674 100644 --- a/examples/simple-photo/client/main.js +++ b/examples/simple-photo/client/main.js @@ -11,9 +11,16 @@ if (Meteor.isClient) { width: 800, height: 600 }; + if (Meteor.isCordova) { + cameraOptions.destinationType = 'URI' + } MeteorCamera.getPicture(cameraOptions, function (error, data) { - Session.set("photo", data); + if (Meteor.isCordova) { + Session.set("photo", WebAppLocalServer.localFileSystemUrl(data)) + } else { + Session.set("photo", data); + } }); } }); diff --git a/examples/simple-photo/package.json b/examples/simple-photo/package.json index 1040f31..cc2cd5d 100644 --- a/examples/simple-photo/package.json +++ b/examples/simple-photo/package.json @@ -10,6 +10,6 @@ "dependencies": { "@babel/runtime": "^7.15.4", "jquery": "^3.6.0", - "meteor-node-stubs": "^1.0.3" + "meteor-node-stubs": "^1.1.0" } } diff --git a/packages/mdg:camera/CHANGELOG.md b/packages/mdg:camera/CHANGELOG.md index bff4892..9f1f609 100644 --- a/packages/mdg:camera/CHANGELOG.md +++ b/packages/mdg:camera/CHANGELOG.md @@ -2,7 +2,7 @@ ## v1.7.0, 2021- -* Add option for Cordova to select `destinationType` on Cordova to allow to switch to `FILE_URI` instead of the default `DATA_URL`. +* Add option for Cordova to select `destinationType` on Cordova to allow to switch to `FILE_URI` instead of the default `DATA_URL`. Note, that you will need access to the device file system in order to display the images. ## v1.6.0, 2021-09-02 diff --git a/packages/mdg:camera/README.md b/packages/mdg:camera/README.md index 647b367..fcbab75 100644 --- a/packages/mdg:camera/README.md +++ b/packages/mdg:camera/README.md @@ -15,7 +15,7 @@ Prompt the user to take a photo with their device and get the picture as a Data - `width` An integer that specifies the minimum width of the returned photo. - `height` An integer that specifies the minimum height of the returned photo. - `quality` A number from 0 to 100 specifying the desired quality of JPEG encoding. -- `destinationType` For Cordova ONLY. Pass in `URI` to get back file uri instead of base64 image (the default). +- `destinationType` For Cordova ONLY. Pass in `URI` to get back file uri instead of base64 image (the default). If you want to display the photo taken see [Local Files section](https://guide.meteor.com/cordova.html#accessing-local-files) in the Guide and use the `WebAppLocalServer.localFileSystemUrl()` function for convert the `file://` url. You can use other options from [Cordova Camera Options](https://cordova.apache.org/docs/en/10.x/reference/cordova-plugin-camera/#module_Camera) on Cordova as they get passed on. diff --git a/packages/mdg:camera/photo-cordova.js b/packages/mdg:camera/photo-cordova.js index 3e78c79..0aff44b 100644 --- a/packages/mdg:camera/photo-cordova.js +++ b/packages/mdg:camera/photo-cordova.js @@ -1,12 +1,15 @@ MeteorCamera.getPicture = function (options, callback) { + var URIMode = false // if options are not passed if (! callback) { callback = options; options = {}; + } else if (options.destinationType === 'URI') { + URIMode = true } var success = function (data) { - if (options.destinationType === 'URI') { + if (URIMode) { callback(null, data); } else { callback(null, "data:image/jpeg;base64," + data); @@ -22,7 +25,7 @@ MeteorCamera.getPicture = function (options, callback) { quality: options.quality || 49, targetWidth: options.width || 640, targetHeight: options.height || 480, - destinationType: options.destinationType === 'URI' ? Camera.DestinationType.FILE_URI : Camera.DestinationType.DATA_URL + destinationType: URIMode ? Camera.DestinationType.FILE_URI : Camera.DestinationType.DATA_URL }) ); }; From 53846b37103a9a2419f85c0d9adffbdefcccb117 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 15 Oct 2021 11:24:46 +0200 Subject: [PATCH 3/3] Published mdg:camera@1.7.0 --- packages/mdg:camera/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mdg:camera/CHANGELOG.md b/packages/mdg:camera/CHANGELOG.md index 9f1f609..9cfcc7f 100644 --- a/packages/mdg:camera/CHANGELOG.md +++ b/packages/mdg:camera/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v1.7.0, 2021- +## v1.7.0, 2021-10-15 * Add option for Cordova to select `destinationType` on Cordova to allow to switch to `FILE_URI` instead of the default `DATA_URL`. Note, that you will need access to the device file system in order to display the images.