Closed koolll closed 9 years ago
I don't see base64 support, so I suppose it is not supported. Would be nice to have it, but if you need to convert URI to base64 there are some solutions on web to easily obtain it using cordova's file API.
But I think it would be a very time consuming process for multiple images.
No it doesn't. Base64 strings tend to result in memory issues so we avoid them. Is there some specific thing you can't do with the file path?
You can use the cordova/phonegap file plugin to copy/move/delete temporary files: https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md
@koolll I have a fork that returns base64 encoded images on both ios and android instead of the file URI's
@jakecraige hi, thanks . i solve this issue by using canvas convert to base64. let me noe if need example
We're not going to add this going forward. We would consider a PR with this functionality added though.
@koolll May I know how you use canvas convert to base64 in cordova-imagePicker?
@jakecraige hi, thanks . i solve this issue by using canvas convert to base64. let me noe if need example
@koolll May I know how you use canvas convert to base64 in cordova-imagePicker?
What you need in your controller
function convertImgToBase64URL(url, callback, outputFormat){
var img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = function(){
var canvas = document.createElement('CANVAS'),
ctx = canvas.getContext('2d'), dataURL;
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL(outputFormat);
callback(dataURL);
canvas = null;
};
img.src = url;
}
Using it
get the uri from plugin
if (window.cordova) {
window.imagePicker.getPictures(
function (results) {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
convertImgToBase64URL(uri, function(base64Img){
// Base64DataURL
});
}
}, function (error) {
}, {
maximumImagesCount: 10,
width: 800
}
);
};
Reference
// is the uri that you get from the plugin
var example_uri = "file:///var/mobile/Containers/Data/Application/56AF7EEA-C8FD-4E2D-BE6A-16BAAA29E87D/tmp/cdv_photo_014.jpg"
convertImgToBase64URL(example_uri, function(base64Img){
// Base64DataURL
});
Hi, i love your plugin so much. But is this plugin support return base 64 instead of getting file path? btw hw to delete temporary image?