Page 1 of 1

Can't upload image to server with headers.

Posted: Sat Apr 19, 2014 9:31 am
by YoshiTiquish

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.


Can't upload image to server with headers.

Posted: Sat Apr 19, 2014 7:36 pm
by Alena Prykhodko

Hello,

Are there any error in console http://docs.appery.io/documentation/d...?


Can't upload image to server with headers.

Posted: Mon Apr 21, 2014 7:25 pm
by YoshiTiquish

Hi, dont worry, I already solved, and is working great.


Can't upload image to server with headers.

Posted: Mon Apr 21, 2014 7:35 pm
by YoshiTiquish

Now im having a little issue, but I dont know if you're having any issues rigth now, I'm trying to save the proyect but the operation get aborted and the UI says "Oops - an error occurred. Please try again in a few seconds!"

Image


Can't upload image to server with headers.

Posted: Mon Apr 21, 2014 9:55 pm
by YoshiTiquish

its working now... thanks :P


Can't upload image to server with headers.

Posted: Mon Apr 21, 2014 10:04 pm
by Illya Stepanov

Thanks for the update!