我正在将图像上传到 asmx Web 服务。文件上传工作正常,但我想知道如何访问我在 javascript 中为文件传输设置的参数。
我想将图像编号传递给 asmx SaveImage web 方法。然后在文件成功保存后,我想将图像编号返回给 Javascript。
//Javascript调用Web服务函数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 网络服务
[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";
}