I am working on a phonegap (versino -4.0) application and we have a functionality to get image either from camera or from photo library.
the code we are using for getting image from photolibrary is
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: source });
This is the example from here
By this code photolibrary is loading in iphone but not working on iPad.
Can you please guide us if anything wrong is here?
Thank you so much for any hint or solution.
Try
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL
});
Also I think popover must be involved for iPad. Check examples again from your link.
setTimeout(function() {
// do your thing here!
}, 0);
Related
I'm using the cordova-plugin-camera to take a picture with these options:
quality: 100,
destinationType: Camera.DestinationType.NATIVE_URI,
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: false,
saveToPhotoAlbum: true,
correctOrientation: true
This is working and I get an URL / Path like this:
assets-library://asset/asset.JPG?id=FBA79210-5E65-4C9B-BF19-9F1169B777C0&ext=JPG
Then, I want to convert this path to a cdvfile:// to display the image in an tag.
window.resolveLocalFileSystemURL(imageURI, function(fileEntry) {
const url = fileEntry.toInternalURL()
})
This is also working and I get:
cdvfile://localhost/assets-library/asset/asset.JPG?id=FBA79210-5E65-4C9B-BF19-9F1169B777C0&ext=JPG
But the image is not rendered. I tried to add <access origin="cdvfile:*" /> in my config.xml but that's not working either. How can i get a valid path / url to display the image?
Best wishes,
Joeri
I had the same problem and managed to solve it with a different approach. After getting the cdvfile url I used Photo Library plugin to get the blob file through the getPhoto method passing the id present in the cdvfile url and with this in hand I got the img source working with the base64data as below:
photoLibrary.getPhoto('FBA79210-5E65-4C9B-BF19-9F1169B777C0').then((blob)=>{
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
var base64data = reader.result;
img.src = base64data;
}
});
UPDATE
You can also use getThumbnail function to improve your page loading depending on the quality, size and quantity of photos you app is supposed to handle.
It just driving me crazy why it is not working. It should be very simple.
I added the plugin using the CLI command. I am sure it is a beginner question, but I just don't get it.
Then I have a "button" called "prendrephoto1". When click it should take a picture. But when button click, just nothing happen on the Xcode Ios Simulator.
I use JqueryMobile and Cordova.
$(document).ready(function(){
var photo1;
var photo2;
$("#prendrephoto1").bind("click",prendrephoto);
function prendrephoto(){
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('ca ne marche pas');
alert('Failed because: ' + message);
}
};
//DERNIERE BALISE JQUERY
});
The iOS simulator does not provide capture simulation, you'll need to run your app on an actual device to retrieve a picture from the camera.
I am running into an issue with just iPhone 6 and 6 Plus running on iOS 8.2 or higher, after taking a photo, I am unable to upload a photo to the Webview.
The app is built using Cordova 5.0.0. It works fine on iPhone 5.
Thanks for any help.
JS
navigator.camera.getPicture(function(e) {
console.log("TakePhoto:" + JSON.stringify(e));
that.__onMediaSuccess(e, FORMAT_IMAGE, onError);
},
onError, {
quality: 75,
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: 800,
targetHeight: 800,
saveToPhotoAlbum: true,
correctOrientation: true
});
I'm using the following code to try to select a photo from the iOS photo library:
navigator.camera.getPicture(this.onCaptureSuccess, this.onCaptureFail, {
allowEdit: true,
correctOrientation: true,
destinationType: Camera.DestinationType.FILE_URI,
soureType: Camera.PictureSourceType.PHOTOLIBRARY,
targetHeight: 315,
targetWidth: 320
});
I'm using iOS 7 (7.0.4) on an iPhone 5s and PhoneGap 3.3.0. No matter what I do it always brings the camera up. What am I doing wrong?
Think I found it:
soureType: Camera.PictureSourceType.PHOTOLIBRARY,
should be:
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
sourceType has a typo in it. Maybe thats it?
Below code is for access gallery photos:
Camera.sourceType = Camera.PictureSourceType.PHOTOLIBRARY
or
Camera.PictureSourceType.SAVEDPHOTOALBUM,
then a photo chooser dialog is shown, from which a photo from the album can be selected.
Using cordova 2.8.1 I am trying to do a camera.getPicture with photolibrary. It seems to be working for android but not for iOS. below is how I call the getPicture code. On an iPhone 4s with iOS 6 it allows me to select an image, but as soon as thats done the error callback is called with the argument being null
var options = {
quality : 30,
destinationType : Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation: true,
targetWidth: 800,
targetHeight: 800
};
navigator.camera.getPicture(this.captureSuccessPre, this.captureError, options);
I was told to add a timeout around the console.logs. On phonegaps documentation it states to do so around alerts. Below is my error callback. which logs [error null]
captureError: function(error){
setTimeout(function(){
console.log("error " + error); //logs error null
}, 100);
}
Anyone have any ideas. I have been struggling for a few days. If it helps any this code works perfect with
sourceType : Camera.PictureSourceType.CAMERA,
I have exactly the same problem; seems to be related to the DestinationType.FILE_URI.
Try this:
var options = {
quality : 30,
destinationType: navigator.camera.DestinationType.NATIVE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation: true,
targetWidth: 800,
targetHeight: 800
};
Looks like there was a bug in 2.8.0 - if you upgrade to 2.9.0 it fixes it ([CB-3757] camera.getPicture from photolib fails on iOS - https://github.com/phonegap/phonegap/blob/2.9.0/changelog)
Try this it will helping for you
function uploadFromGallery(){
navigator.camera.getPicture(uploadPhoto,function(message){
console.log('get picture failed'); },
{quality: 75,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY,
allowEdit:true,
targetWidth: 100,
targetHeight: 100
});
}