如何使用phonegap FileTransfer参数.asmx Web服务 [英] How to use phonegap FileTransfer parameters with .asmx web service
问题描述
我正在将图片上传到asmx网络服务。文件上传工作正常,但我想知道如何访问我在文件传输的javascript中设置的参数。
I am uploading an image to an asmx web service. The file upload works fine, but I am wondering how to access the parameters that I set in the javascript for the filetransfer.
我想传递图像号到asmx SaveImage web方法。
I want to pass the image number to the asmx SaveImage web method. Then after the file has successfully been saved I want to return the image number to the Javascript.
// JavaScript调用Web服务
function uploadPhoto(imageURI,imageNumber ){
//Javascript Calling Web Service function uploadPhoto(imageURI, imageNumber) {
var options = new FileUploadOptions(),
params = {},
ft = new FileTransfer(),
percentLoaded = 0.0,
progressBar = $(".image" + imageNumber + " > .meter > span");
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
params.value1 = "test";
params.value2 = "param";
options.params = params;
//get progress of fileTransfer for progress bar
ft.onprogress = function (progressEvent) {
if (progressEvent.lengthComputable) {
percentLoaded = Math.round(100 * (progressEvent.loaded / progressEvent.total));
progressBar.width(percentLoaded + "%");
} else {
//loadingStatus.increment();
}
};
ft.upload(imageURI, "http://mysite.com/test/uploadPhotos.asmx/SaveImage", win, fail, options);
}
//。asmx web service
//.asmx web service
[WebMethod]
public string SaveImage()
{
string rootPathRemote = WebConfigurationManager.AppSettings["UploadedFilesPath"].TrimEnd('/', '\\') + "/";
string rootPhysicalPathRemote = rootPathRemote + "\\";
int fileCount = 0;
fileCount = HttpContext.Current.Request.Files.Count;
for (int i = 0; i < fileCount; i++)
{
HttpPostedFile file = HttpContext.Current.Request.Files[i];
string fileName = HttpContext.Current.Request.Files[i].FileName;
if (!fileName.EndsWith(".jpg"))
{
fileName += ".jpg";
}
string sourceFilePath = Path.Combine(rootPhysicalPathRemote, fileName);
file.SaveAs(sourceFilePath);
}
return "test";
}
推荐答案
asmx web方法你可以使用Request.Params ...
To get the parameters passed to the asmx web method you can use the Request.Params...
我将以下行添加到我的代码
I added the following lines to my code
javascript //使用imageNum键添加参数
javascript //add a parameter with a key of imageNum
params.imageNum = imageNumber;
添加到.asmx [Web方法]
added to .asmx [Web Method]
string allParams = "";
NameValueCollection parameters = HttpContext.Current.Request.Params;
string[] imageNum = parameters.GetValues("imageNum");
for (int j = 0; j < imageNum.Length; j++)
{
allParams += imageNum[j].ToString();
}
这篇关于如何使用phonegap FileTransfer参数.asmx Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!