Can't upload image to server with headers.
Im trying yo upload a image taking from the camera or album.
Avoiding the headers on my MVC Web Api Post, everything is fine.
But when I change the code asking for some headers I need for authentication the FileTransfer stops working. I add the required headers on options.headers and in options.params but I receive error = 1.
--------var fileURI = localStorage.getItem('imgUriSeleccionada');
var win = function(r) {
alert('done');
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
};
var fail = function(error) {
alert("An error has occurred: Code = " + error.code);
alert("upload error source: " + error.source);
alert("upload error target " + error.target);
};
var options = new FileUploadOptions();
options.headers = {
token : localStorage.getItem("AuthToken"),
idU : localStorage.getItem("idUser"),
Connection: "close"
};
options.fileKey="file";
options.chunkedMode = false;
options.mimeType = 'image/jpeg';
options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType="text/plain";
var params = new Object();
params.headers = {
token : localStorage.getItem("AuthToken"),
idU : localStorage.getItem("idUser"),
Connection: "close"
};
options.params = params;
var uri = encodeURI("https://URLtoUploadFile");
var ft = new FileTransfer();
ft.upload(fileURI, uri, win, fail, options);
I added as a Rest Service in the Appery SDK, added the request params marked as headers and use the test module to check if is my MVC Web Api service that is wrong, but im receiving the correct answer and the service is responding. Thats why i'm thinking the FileUpload is the wrong here.