I have a function that upload a file to the server and then upload normal json data.
here is my code:
$scope.sendPost = function() {
//normall data
var postData = {
name: shareData.returnData()[0].title,
content: shareData.returnData()[0].content,
category1: category1,
category2: category2,
category3: category3,
category4: category4,
category5: category5,
};
//upload image post
var options = {};
options.fileKey='avatar';
$cordovaFile.uploadFile('http://10.0.0.4:1337/posts/newPost', shareData.returnData()[0].image, options).then(function(result) {
postService.sendData("http://10.0.0.4:1337/posts/newPost", postData); //after the file upload
}, function(err) {
// Error
}, function (progress) {
// constant progress updates
});
}
this code works but since i need to synth between the file and the data i cannot send them one by one. how can i send data + cordova camera file to the server in one go?