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.
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 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
[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";
}