1

How to send photos from android contacts to my server ? I'm using cordova 2.9.0

var file = 'content://com.android.contacts/contacts/1/photo';

    Camera.DestinationType.DATA_URL = file;
    navigator.camera.getPicture(function(imageURI){

        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
        options.mimeType="image/jpeg";

        var params = {};
        params.uid = device.uuid;

        options.params = params;

        var ft = new FileTransfer();
        ft.upload(imageURI, encodeURI(this.server + '/upload.php'), function(r){
            console.log("Code = " + r.responseCode);
            console.log("Response = " + r.response);
            console.log("Sent = " + r.bytesSent);
        }, function(error){
            alert("An error has occurred: Code = " + error.code);
            console.log("upload error source " + error.source);
            console.log("upload error target " + error.target);
        }, options);        

    }, function(){ console.log('file fail'); }, {
        destinationType: Camera.DestinationType.DATA_URL,
        sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
        correctOrientation: true
      });
Amith
  • 6,199
  • 6
  • 28
  • 45

0 Answers0