import { DomSanitizer } from '@angular/platform-browser';
/////
constructor(private DomSanitizer: DomSanitizer){}
//////
uploadImage(){
this.camera.getPicture({
quality: 100,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: this.camera.DestinationType.FILE_URI
}).then((imageData) => {
this.selectedImage = imageData; /// passing it to variable to be used in html side
}, (err) => {
console.log(err);
});
}
I’ve always used data_url so I don’t have the knowledge to provide. But I do see you provide a target width and not a target height. Maybe that’s causing some unforeseen issue.
Also, though unsure if this advice is contrary to best practices, I have always bypassed explicitly typing my options as CameraOptions. As in,
let options = {
sourceType: this.camera.etc..
}
this.camera.getPicture(options).then...
Ok I figured it out, the problem was due to a bug in Ionic Framework that prevents images from being loaded when using the -lc switch. I used ionic cordova run adroid without -lc and the image was shown.
I am using ionic cordova run android --c and if I remove --c it works but the urls that I am calling from the server do not. However when I run with --c images from server are shown but not from the mobile storage. Did you find any solution other then removing your debugging tools?
HI, I have a question.
I creating an image, and then moving it to the device store in a folder called saved_images.
That part is working correctly, but then in the this.camera.getPicture
i getting the correct url, and I already tried domsanitizer, normalizeUrl and even cut off the file: section from the beginning, but keep getting the Not allowed to load local resource: error: file:///storage/emulated/0/Android/data/io.ionic.starter/files/saved_images/1533891361209.png
I also saw, that there is a problems with the -l and -c flags.
but I’m running the app with this script ionic cordova run android.
even if I building it the errors remain.
What else could be the error?
This FileReader solution is working, but there is two problems.
It’s really slow
It’s using the base64encoded image.
Actually this is the reason why is it slow, because it’s hard to load the image.
I can’t beleive that there is no working solution for this.
And by the way, I’m using Galaxy S9 +
this.camera.getPicture(options).then((imageData) => {
//needs to import file plugin
//split the file and the path from FILE_URI result
let filename = imageData.substring(imageData.lastIndexOf('/')+1);
let path = imageData.substring(0,imageData.lastIndexOf('/')+1);
//then use the method reasDataURL btw. var_picture is ur image variable
this.file.readAsDataURL(path, filename).then(res=> var_picture = res );