Currently I have this code right now,
In my html page, on the form I have this:
<input type="file" id="txtUploadFile" accept="image/*" onchange="changetext();"/>
I upload the picture using javascript on my doUpload()
function
function doUpload() {
var srwebserviceURL = "/Webservices/Facilities/ServiceRequest.asmx";
var sMsgBody = "<filePath>" + txtUploadFile.value + "</filePath>";
var a = sendSoapMsg(srwebserviceURL, "SaveSRLogoPhotoSite", sMsgBody, "SaveSRLogoPhotoSiteResult");
}
So as you can see from the code above, I am passing the file path of the photo to my webservice.
On my webservice, the SaveSRLogoPhotoSite
, I have the ff. code:
public SRLogoPhoto SaveSRLogoPhotoSite(string filePath)
{
DataSet ds = null;
Hashtable param = new Hashtable();
SRLogoPhoto srlp = new SRLogoPhoto();
try
{
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
Byte[] b = new Byte[fs.Length];
fs.Read(b, 0, b.Length);
fs.Close();
SqlParameter P = new SqlParameter("@Picture", SqlDbType.VarBinary, b.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, b);
string sqlStr = "UPDATE SRSiteLogo SET srImage = @Picture ";
param.Add("Picture", P);
ds = dbHelper.GetDataSet(sqlStr, param);
}
catch (Exception ex)
{
srlp.Error = "SaveSRLogoPhotoSite() web method failed on call to dbHelper.GetDataSet - " + ex.Message;
}
return srlp;
}
This is working on my local pc. But it does not seem to work when I deploy it to an environment other than my pc. When I try to debug in soapUI, it says that it cannot find the file path.
It seems that the filepath I should pass on my webservice should be on the server first instead of the filepath of the current filesystem of the pc it is in.
How do I do that?
--edit-- I was informed that this is possible using ajax..I'm new to ajax and don't know how to do it..
Thank you in advance