How send array in fileTransfer option object in ionic 2

713 Views Asked by At

I want to save the image using fileTransfer in Ionic 2.

How to send array in fileTransfer object. I didn't get it on the server side.

   var options = {
      fileKey: "file",
      fileName: filename,
      chunkedMode: false,
      mimeType: "image/jpg",
      headers : {},
      params: {
        'file': filename,
        'rId': this.rId,
        'model':{ 'RId': this.rId }
      }
    };

    const fileTransfer: TransferObject = this.transfer.create();

    fileTransfer.upload(targetPath, url, options).then(data => {
      console.log(data);
    }, err => {
      console.log("Upload Err : "+ err);
    });
  }

Here at server side rId and file values are getting but model is not displaying any value.

1

There are 1 best solutions below

0
karan sharma On

Try converting the object to JSON and then sending it in the model parameter and then on the server side, use JSON decode method to get the original object.

e.g.

var modelObj = JSON.stringify({ 'RId': this.rId });

var options = {
  fileKey: "file",
  fileName: filename,
  chunkedMode: false,
  mimeType: "image/jpg",
  headers : {},
  params: {
    'file': filename,
    'rId': this.rId,
    'model': modelObj
  }
};