Thursday, September 27, 2018

javascript - Send image and json data to server in a ionic application

I'm developing an application for android.
In my controller I am trying to send an image and a JSON to the server.



I capture the image with the camera plugin and then I use $cordovaFileTransfer to send image and a json object to the server.
The server support multiform request.




What I did it's something like that:





// Destination URL
var url = "http://example.gajotres.net/upload/upload.php";

//File for Upload
var targetPath = "myImage.jpg";


// File name only
var filename = targetPath.split("/").pop();

var options = { fileKey: "file", fileName: filename, chunkedMode: false, mimeType: "image/jpg" }

var params = {};
params.info = {
aaaa : "zeze",
zeze : "aaza",
info = {

ere: 45,
azeae: "ezrz"
}
}

options.params = params;

$cordovaFileTransfer.upload(url, targetPath, options).then(function (result) {
console.log("SUCCESS: " + JSON.stringify(result.response)); }, function (err) { console.log("ERROR: " + JSON.stringify(err)); }, function (progress) { // PROGRESS HANDLING GOES HERE });




Server side I check the received data and everything is fine but the form "info" has no Content-Type: application/json so the server cannot interpretate it.
I need to send a multiform request and specify for each form the content-type.



Do you have a solution?



Thanks

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...