YoshiTiquish
Posts: 0
Joined: Sat Apr 19, 2014 9:31 am

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.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Can't upload image to server with headers.

Hello,

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

YoshiTiquish
Posts: 0
Joined: Sat Apr 19, 2014 9:31 am

Can't upload image to server with headers.

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

YoshiTiquish
Posts: 0
Joined: Sat Apr 19, 2014 9:31 am

Can't upload image to server with headers.

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

YoshiTiquish
Posts: 0
Joined: Sat Apr 19, 2014 9:31 am

Can't upload image to server with headers.

its working now... thanks :P

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Can't upload image to server with headers.

Thanks for the update!

Return to “Issues”