PhoneGap file transfer plugin parameters to ASP.NET service

混江龙づ霸主 提交于 2019-12-11 19:27:31

问题


I want to pass parameters from the PhoneGap file transfer plugin to an ASP.NET MVC web service.

So I prepared Params in JavaScript :

 var Params = {};
    Params.Order = $("#Order").val();
alert($("#Order").val());//It works it is not null
    Params.latitude = $("#latitude").val();
    Params.longitude = $("#longitude").val();
    options.Params = Params;
    ft = new FileTransfer();
    ft.upload(sPicData, encodeURI("../Mobile/UploadPhoto"), win, fail, options);

Now I want to acces the Params from my ASP.NET MVC web service, but this code gives an error (Null exception).

   [HttpPost] 
    public JsonResult  UploadPhoto()
    {
         // File upload code here and it works well.
         // File upload work but there is problem with Params
         System.Collections.Specialized.NameValueCollection parameters = Request.Params;
         string[] imageNum = parameters.GetValues("Order");
// string order=imageNum[0]
         string[] latitude = parameters.GetValues("latitude");
         string[] longitude = parameters.GetValues("longitude");
//other codes
    }

回答1:


function photoUpload() {

    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = sPicData.substr(sPicData.lastIndexOf('/') + 1);
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;
    var params = new Object();

    navigator.geolocation.getCurrentPosition(
        function(position) {
        params.fileKey = "file";
        params.longitude = position.coords.longitude;
        params.latitude = position.coords.latitude;
        params.altitude = position.coords.altitude;
        params.accuracy = position.coords.accuracy;
        params.altitudeAccuracy = position.coords.altitudeAccuracy;
        params.heading = position.coords.heading;
        params.speed = position.coords.speed;
        params.timestamp = position.timestamp;

        //alert(params.longitude + ',' + params.latitude);

        options.params = params;

        ft = new FileTransfer();
        ft.upload(sPicData, "http://YOURSERVER/upload.aspx", win, fail, options); 
        });

}

Try this, it works for me. Just grab the geo data in the different params as ordinary posted form fields.




回答2:


I ran into the same problem here. How to use phonegap FileTransfer parameters with .asmx web service

Try changing

System.Collections.Specialized.NameValueCollection parameters = 
    Request.Params;

to

System.Collections.Specialized.NameValueCollection parameters = 
    HttpContext.Current.Request.Params;


来源:https://stackoverflow.com/questions/31493196/phonegap-file-transfer-plugin-parameters-to-asp-net-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!