I am currently trying to implement Android App
using Phonegap ionic framework
. My requirement is to upload an image from gallery to remote server. To achieve this I implemented ASP.NET
REST API
to upload image to server. (Let assume my URL to upload: http://XXXX.net/api/Upload
). Inside my REST API I implemented UploadController:WebController
. I has a Post() method which looks like below.
Server Code:
public string Post()
{
HttpPostedFile MyFile = HttpContext.Current.Request.Files["recFile"];
if (MyFile == null)
return null;
return Utils.UploadToServer(file);
}
My Android code looks like below:
$scope.UploadPictureEx = function()
{
var options = new FileUploadOptions();
options.fileKey="recFile";
options.fileName=$scope.emplyeedata.ImageURI.substr($scope.emplyeedata.ImageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
options.httpMethod = "POST";
options.headers = {
Connection: "close"
};
var ft = new FileTransfer();
ft.upload($scope.emplyeedata.ImageURI, "http://XXXX.net/api/Upload/", win, fail, options);
}
Thats it. When I execute I always getting error saying Error code = 3
. Can any one please let me know how to get this done?
Is my approach of implementing Web API is correct? Am I doing some thing wrong?
Thanks!!
Have you enabled cors in your web api ?