$cordovaFileTransfer.upload show nothing, no error or success messege


#1

hi guys, would you please to see my code here, i’m tryng this but $cordovaFileTransfer.upload do nothing, no succes messege or error, would you guys please tell whats wrong, i have no idea because i’m new in this ionic…thanks
this my code, i’m tryng using somebody tutorial in internet :

$scope.openPhotoLibrary = function() {
//alert(“X”);
var options = {
quality: 85,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
targetWidth: 200,
targetHeight: 200,
};

$cordovaCamera.getPicture(options).then(function(imageData) {
	alert("1");

    //console.log(imageData);
    //console.log(options);   
    var image = document.getElementById('tempImage');            
    image.src = imageData;
    $scope.imgURI = imageData;
    alert("2");
    var server = "http://192.168.88.10/upload.php";
    	alert("3");
        filePath = imageData;
        alert("4");

    var date = new Date();
    	alert("5");
    var options = {
        fileKey: "file",
        fileName: imageData.substr(imageData.lastIndexOf('/') + 1),
        chunkedMode: false,
        mimeType: "image/jpg"
    };
    alert("6");
    $cordovaFileTransfer.upload(server, filePath, options).then(function(result) {
    	alert("Z");
        console.log("SUCCESS: " + JSON.stringify(result.response));
        console.log('Result_' + result.response[0] + '_ending');
        alert("success");
        alert(JSON.stringify(result.response));
        alert("7");

    }, function(err) {
    	alert("error");
        console.log("ERROR: " + JSON.stringify(err));
        //alert(JSON.stringify(err));
    }, function (progress) {
    	alert("progress");
        // constant progress updates
    });


}, function(err) {
    // error
    console.log(err);
});

}


#2

import { Transfer, TransferObject } from ‘@ionic-native/transfer’;

declaring TransferObject like this
private fileTransfer: TransferObject;

this.fileTransfer.upload(this.targetPath, this.apiPath, options)
          .then((data) => {
            console.log("File upload successful! ", data)
            this.presentToast("File upload successful. Please proceed now.");
            this.navCtrl.push(HomePage);
          }, (err) => {
            console.log("File upload error. ", err)
            this.presentToast("File upload error. Please try later.");
          })

In params you can send your extra data

private params = {
    user_id: ' ',
    user_name: ' '
  }

Define options like this and set header in it.

 var options = {
          fileName: this.lastFile,
          params: this.params,
          mimeType: "image/jpeg",
          headers: {
            'Authorization': 'Basic key'
          }
        };

I think this solution will work for you


#3

thanks,
but, is that working with Ionic v1?


#4

Give a try. I hope this will work on Ionic1 as well.

I implemented this solution on ionic2.


#5

ok, thanks for you’re help…
i’am trying now…