I need to send in background multiple-image and some data to server.
I'm using ionicframework (with angularjs) for my android app. I'm using angular-file-upload (directive) and the following code is my factory:
if(angular.isArray(arrPictures) && arrPictures.length > 0) {
var files = [];
for(var i=0; i<arrPictures.length; i++) {
files.push(arrPictures[i].photo); //it is like file://my_path/myImage.jpg
}
$upload.upload({
url: API_POST_ANSWER,
method: 'POST',
data: {
"idSurvey": idSurvey,
"idOAM": idOAM,
"idOPM": idOPM,
"score": score,
"date": date,
"answerJson": answersJson,
"address": address,
"latitude": latitude,
"longitude": longitude
},
file: files,
fileFormDataName: "pictures"
}).progress(function (evt) {
//progress
alert('progress: ' + parseInt(100.0 * evt.loaded / evt.total) + '% file :'+ evt.config.file.name);
}).success(function (data, status, headers, config) {
// file is uploaded successfully
alert('file ' + config.file.name + 'is uploaded successfully. Response: ' + data);
}).error(function (ex) {
//error
alert("error");
alert(ex);
});
}
Now i have a problem because the server get strings (path string) and not files My question is "How i can convert my path string into file object to send it currectly to the server?"
My solution was to convert the image into base64 and store it into local db (using sqllite). After that when i want to send the image: i query my db, i get the base64 string and send it to my rest services.
All this solution whitout using $upload directive but $http service.