cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mamillapalli, Balachandra" <Balachandra.Mamillapa...@appliedis.com>
Subject Image upload using FileTransfer.Upload to ASP.NET REST API
Date Thu, 17 Apr 2014 07:40:53 GMT
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!!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message