Hey so mdg:camera appears to be dead as dead even chrome won’t work with it anymore because of some very new changes.
Does anyone have an example of directly using cordova-plugin-camera I’ve tried install different versions but using a regular import like doesn’t work to well. I’ve tried a few syntax methods doinga direct meteor add cordova: call and using a regular meteor npm install.
import camera from ‘cordova-plugin-camera’;
I’m on Meteor 1.8 doesn’t seem to cause to many issues and I am using a modified version of raix push so preferrably something that can work alongside this
1 Like
if(Meteor.isCordova) {
const Camera = navigator.camera;
const options = {
quality: 30,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true,
correctOrientation: true
}
Camera.getPicture(
(imageUri) => {
const uri = WebAppLocalServer.localFileSystemUrl(imageUri);
//do something with the uri here
},
(error) => {
console.debug("Unable to obtain picture: " + error, "app");
},
options)
}
You don’t need to do an import
because Cordova is putting everything up as a global 
If you then want to display the photo, you can simply set the src
of an img
tag to the uri
.
If you want to upload the photo via a Meteor method, this did work for me:
if(Meteor.isCordova) {
window.resolveLocalFileSystemURL("file:/"+uri, fileEntry => {
fileEntry.file(file => {
let reader = new FileReader();
reader.onloadend = e => {
Meteor.call("uploadImages", e.target.result);
}
reader.readAsDataURL(file);
})
}, error => {
console.log("Error uploading file:");
console.log(error);
})
Of course you can also do reader.readAsBinaryString()
or similar.
Oh, and everything other than a "file:/"+uri
(i.e. more or less than one slash) will either result in an access denied error or a 404.
Works in both iOS and Android. For the browser I went another route.