Access the Photo Library in your Meteor Cordova App


by Spencer Carli

If your Meteor Cordova app needs access to the device camera you’ll likely want to also allow the user to access their photo library. It’s simple when you use the

mdg:camera

package.

When you use the package you pass in a few options, like so…

var options = {
  width: 350,
  height: 350,
  quality: 75
}
MeteorCamera.getPicture(options, function(err, data) {
  if (err) {
    console.log('error', err);
  }
  if (data) {
    Session.set('img', data)
  }
});

This will access the device camera. It works regardless if you’re on a phone or using a browser on your computer.

Want to be able to access the photo library on mobile? Just pass one additional option in. Like so....

var options = {
  width: 350,
  height: 350,
  quality: 75,
  sourceType: Camera.PictureSourceType.PHOTOLIBRARY
}
MeteorCamera.getPicture(options, function(err, data) {
  if (err) {
    console.log('error', err);
  }
  if (data) {
    Session.set('img', data)
  }
});

Note: Unlike the normal usage of

mdg:camera

when you specify the sourceType it only works through Cordova (only tested on iOS so far).

Here’s a demo repo you can try: https://github.com/spencercarli/meteor-cordova-photolibrary

S/O to @hellogerard for finding this out.

Share Share on Twitter Share on Facebook Share on LinkedIn

How Can We Help?

Reaching out doesn’t mean you’re ready to start a project, but we’d love to learn more about the challenge you’re facing, answer any questions, and see if we might be a good fit for working together.

Contact Us