![](/img/trans.png)
[英]How to post/upload recorded video as blob in MVC using HTML5/ Javascript at client side and C# code at controller?
[英]How to upload blob image from html page using javascript to c# code
目前,我现在有此代码,
在我的html页面上,在表单上有:
<input type="file" id="txtUploadFile" accept="image/*" onchange="changetext();"/>
我在doUpload()
函数上使用javascript上传图片
function doUpload() {
var srwebserviceURL = "/Webservices/Facilities/ServiceRequest.asmx";
var sMsgBody = "<filePath>" + txtUploadFile.value + "</filePath>";
var a = sendSoapMsg(srwebserviceURL, "SaveSRLogoPhotoSite", sMsgBody, "SaveSRLogoPhotoSiteResult");
}
因此,从上面的代码中可以看到,我正在将照片的文件路径传递给我的Web服务。
在我的Web服务SaveSRLogoPhotoSite
,我有ff。 码:
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;
}
这在我的本地PC上工作。 但是,当我将其部署到PC以外的环境中时,它似乎不起作用。 当我尝试在soapUI中调试时,它说找不到文件路径 。
似乎我应该通过我的Web服务传递的文件路径应该首先在服务器上,而不是它所在的PC当前文件系统的文件路径。
我怎么做?
- 编辑 -我被告知使用ajax可以实现此操作。.我是ajax的新手,不知道该怎么做。
先感谢您
在本地运行Web时,需要上载的文件和服务器位于一台计算机上,因此您可以确定文件路径并执行上载任务。 但是,将网站部署到其他服务器时,无法确定路径文件。 您必须将文件转换为流并发送到服务器,读取流,转换为期望的格式然后继续。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.