【问题标题】:PhoneGap file transfer plugin parameters to ASP.NET servicePhoneGap 文件传输插件参数到 ASP.NET 服务
【发布时间】:2016-05-19 00:05:33
【问题描述】:

我想将参数从 PhoneGap 文件传输插件传递到 ASP.NET MVC Web 服务。

所以我在 JavaScript 中准备了Params

 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);

现在我想从我的 ASP.NET MVC Web 服务中访问 Params,但此代码给出了错误 (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
    }

【问题讨论】:

  • GetValues 会在参数不存在的情况下返回 null,是否设置了断点并检查参数集合中是否存在参数
  • 我如何设置断点?移动设备中使用的相机文件传输插件...在我发送值(例如顺序、纬度、经度)之前,我会提醒他们值不为空。但是发送时服务中的服务我无法访问它们,因为它给出了空异常错误
  • 在.net服务中,在访问参数之前设置一个断点,检查是否有任何参数已经发送
  • HttpFileCollectionBase 文件 = Request.Files;这是用文件设置的,但 System.Collections.Specialized.NameValueCollection 参数 = Request.Params;这是空的
  • 尝试使用 var params = {}; (小写)

标签: c# asp.net-mvc cordova file-upload phonegap-plugins


【解决方案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); 
        });

}

试试这个,它对我有用。 只需将不同参数中的地理数据作为普通发布的表单字段获取即可。

【讨论】:

    【解决方案2】:

    我在这里遇到了同样的问题。 How to use phonegap FileTransfer parameters with .asmx web service

    尝试改变

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 2013-10-05
      • 2013-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-21
      相关资源
      最近更新 更多