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
}
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.
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.