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