Reputation: 77
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.
Upvotes: 0
Views: 712
Reputation: 614
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
}
};
Upvotes: 1