Select pictures on iOS/Android and send them to RESTfull api


#1

Hi,

We’ve built an Ionic app where a user could change this avatar which used across the app. We used the https://github.com/wymsee/cordova-imagePicker.git plugin, but the plugin only gave us the local path to the image, where we needed the image data so we could send the data to our server where we could persist it.

We putted our the solution on GitHub: https://github.com/brianvandelden/acato-service-image

var options = {
    maximumImagesCount: 1,
    width: 100,
    height: 100,
    quality: 100
};

$acatoImage.getPictures(options).then(function(results) {
    // loop true results
    for(var i = 0; i < results.length; i++){
        $acatoImage.getImageData(results[i]).then(function(imageData) {
            console.log(imageData, 'imageData');
            // send imageData to server X
        }, function(error) {
            alert(error, 'Error sending imageData to server');
        });
    }
}, function(error) {
    alert(error, 'Error getting pictures');
});

#2

Why don’t you use Cordova File API plugin to access this file, convert it to BASE64 string and send it remotely?

Find mentioned plugin here: http://www.gajotres.net/useful-cordova-plugins-for-your-ionic-application-examples/ plugin No 4.

You’ll also find a working example.


#3

http://plugins.cordova.io/#/package/org.apache.cordova.camera

I used this plugin to take a picture on the device, and then save the base64 encoded string, which is returned by the cordova plugin.

You can setup sourceType to change the source from camera to for example ‘PHOTOLIBRARY’.

And DestinationType to DATA_URI for base64 encoded images.


#4

Because we needed the multi file (image) selector.


#5

This is also a viable solution mainly because it require only one plugin.

Though it has one problem, certain Android devices will not work with sourceType “PHOTOLIBRARY”. For some reason, instead of a photo library it will access certain 3rd party photo library applications leading to error.


#6

Hi inv123,

Nice one!.

We used this methode a while ago, and this plugin you mentioned wasn’t there in that time, but looks that it does the job. Is it also supporting multi image selection? Couldn’t find it in the docs.


#7

So what’s the problem? If this plugin can return an array of image locations you will process them in the loop.


#8

Yes that’s what we did.


#9

Yeah, i think it doesn’t support multi select.


#10

It happens when a user associate a new application to a specific file type, like open .pdf files with some kind of a pdf reader, not the default built in, isn’t it?