image/file
应该在服务器上,以便更改img
标记的src
属性。 src
属性预计图像的URL
。您不能简单地将图像的内容设置为src
。
这表明您需要先将image
转移到服务器。有使用AJAX/JQuery的等各种方式
在ASP .NET最简单的例子是:
<form id="YourForm" runat="server" enctype="multipart/form-data">
<input type="file" id="yourImageFile" name="yourImageFile" />
<asp:Button runat="server" ID="buttonUpload" OnClick="fileUpload" Text="Send Image" />
</form>
您可以在Server
获取内容为:
protected void fileUpload(object sender, EventArgs e)
{
//get the file here
HttpPostedFile fileImage = Request.Files["yourImageFile"];
//You can do whatever you want with fileImage object. Like
BinaryReader bReader = new BinaryReader(fileImage.InputStream);
byte[] binaryData = bReader.ReadBytes(file.ContentLength);
//Convert to Base64
String imageBase64 = Convert.ToBase64String(binaryData);
}
来源
2017-10-07 06:28:23
MKR
并不很清楚你拥有和想要达到的目标,但是知道'img'标记不会将任何内容发回给服务器(类似于其他类似'div'和'head'的),可能会对您有所帮助。 –
在那里,我删除了Java脚本之间的空间对此感到抱歉,我该如何将该图像放在img标记中并获取其字节。它使用Base64字符串值显示图像。我希望该字符串值在 –
@ user7389750后面的代码中转换为字节。您可以使用JavaScript获取内容图像文件,然后直接通过Post请求发送它。 – MKR