You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Mamillapalli, Balachandra" <Ba...@appliedis.com> on 2014/04/17 09:40:53 UTC
Image upload using FileTransfer.Upload to ASP.NET REST API
I am currently trying to implement Android App using phone Gap 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);
}
That's it. When I execute I always getting error saying "Error code = 3". Can anyone please let me know how to get this done?
Is my approach of implementing Web API is correct? Am I doing something wrong?
Thanks!!