我正在尝试从oracle数据库中读取blob并将其转换为base64String,然后将其显示在我的网页中。从oracle读取工作正常并返回数据,但是将图像转换为base64会返回巨大的值(长度= 1 600 000及以上),无法转换为图像并显示在我的页面中(显示损坏的图标图像)。换句话说,我在我的代码中从互联网实现了base64String,一切正常......将blob转换为图像的最佳方法是什么?以下是我的代码:
Dim Conn As String = ConfigurationManager.ConnectionStrings("connString").ConnectionString
Dim cnnConnection As New OracleConnection(Conn)
cnnConnection.Open()
Dim cmd As New OracleCommand()
cmd.Connection = cnnConnection
cmd.CommandText = "SELECT d.document_file from T_library_documents d d.library_documents_id=64 ORDER BY d.DOCUMENT_NAME"
cmd.CommandType = CommandType.Text
Dim dr As OracleDataReader = cmd.ExecuteReader
If dr.Read() Then
Dim blob As OracleBlob = dr.GetOracleBlob(0)
Dim byteArr As [Byte]() = New [Byte](blob.Length - 1) {}
Dim i As Integer = blob.Read(byteArr, 0, System.Convert.ToInt32(blob.Length))
blob.Close()
cnnConnection.Close()
Dim imageBase64 As String = Convert.ToBase64String(byteArr)
Dim imageSrc As String = String.Format("data:image/gif;base64,{0}", imageBase64)
img.Attributes("src") = imageSrc
End If