简体   繁体   English

如何使用javascript从HTML页面上载blob图片到C#代码

[英]How to upload blob image from html page using javascript to c# code

Currently I have this code right now, 目前,我现在有此代码,

In my html page, on the form I have this: 在我的html页面上,在表单上有:

<input type="file" id="txtUploadFile" accept="image/*" onchange="changetext();"/>

I upload the picture using javascript on my doUpload() function 我在doUpload()函数上使用javascript上传图片

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. 因此,从上面的代码中可以看到,我正在将照片的文件路径传递给我的Web服务。

On my webservice, the SaveSRLogoPhotoSite , I have the ff. 在我的Web服务SaveSRLogoPhotoSite ,我有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. 这在我的本地PC上工作。 But it does not seem to work when I deploy it to an environment other than my pc. 但是,当我将其部署到PC以外的环境中时,它似乎不起作用。 When I try to debug in soapUI, it says that it cannot find the file path . 当我尝试在soapUI中调试时,它说找不到文件路径

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. 似乎我应该通过我的Web服务传递的文件路径应该首先在服务器上,而不是它所在的PC当前文件系统的文件路径。

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.. - 编辑 -我被告知使用ajax可以实现此操作。.我是ajax的新手,不知道该怎么做。

Thank you in advance 先感谢您


When you run web on local, file that you need upload and server lie on a machine, so you can determine file path and execute upload task. 在本地运行Web时,需要上载的文件和服务器位于一台计算机上,因此您可以确定文件路径并执行上载任务。 Howerver, when you deploy your web to another server, you can't determine path file. 但是,将网站部署到其他服务器时,无法确定路径文件。 You have to convert file to stream and send to server, read stream, convert to expect format and go ahead. 您必须将文件转换为流并发送到服务器,读取流,转换为期望的格式然后继续。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用客户端的HTML5 / Javascript和控制器的C#代码将MVC中的录制视频作为blob发布/上传? - How to post/upload recorded video as blob in MVC using HTML5/ Javascript at client side and C# code at controller? 如何使用C#仅将第一页从Multipage Blob .Tiff图像转换和显示为.Jpeg - How to Convert and display only the first page from Multipage Blob .Tiff image to .Jpeg using C# 从HTML网页(C#)将文件上传到Azure Blob吗? - Upload file to Azure Blob from HTML webpage (C#)? 如何在 C# 中将图像从本地系统上传到 azure blob 存储 - How to upload image from local system to azure blob storage in c# 如何使用WebClient在C#中下载图像并使用Javascript从ASPX页面获取图像 - How to Download image in c# using webclient and use Javascript to get image from aspx page 如何使用 C# 将文件上传到 Azure Blob 存储? - How to upload file into Azure Blob Storage using C#? 如何使用C#将DataTable上传到Azure Blob存储? - How to upload a DataTable to Azure Blob Storage using C#? 如何从c#中的URL将文件直接上传到azure blob? - How to upload a file directly to azure blob from the URL in c#? 使用 C# 从 html 页面检索 javascript 属性 - Retrive javascript properties from html page using C# 使用JavaScript在HTML页面上从C#显示计时器 - Showing timer from c# on html page using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM