⑴ web圖片一般存在後端哪裡
web圖片一般存在Java後端。
web前端上傳圖片到Java後端,並保存到本地。一般來說,圖片在後端的存儲方式分為兩種:一,可以將圖片以獨立文件的形式存儲在伺服器的指定文件夾中,再將路徑存入資料庫欄位中,二,將圖片轉換成二進制流,直接存儲到資料庫的Image類型欄位中。
⑵ 如何才能往資料庫里讀取圖片數據或者從資料庫里讀圖片
給你提供個ACCESS版的VB代碼,使用時調用這些過程即可:
'使用ADODB.Stream來保存/讀取圖像文件到資料庫
'引用Microsoft ActiveX Data Objects 2.5 Library及以上版本
'保存文件到資料庫中
Sub SaveFile()
Dim Stm As New ADODB.Stream
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCnn As String
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & _
App.Path & "\DB1.mdb"
Cnn.Open strCnn
'讀取文件到內存(二進制模式)
With Stm
.Type = adTypeBinary
.Open
.LoadFromFile App.Path + "\Image1.bmp"
End With
With rs
.Open "SELECT * FROM TABLE1", Cnn, 1, 3
.AddNew
.Fields("IMAGE") = Stm.Read
.Update
End With
rs.Close
Stm.Close
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub
'從資料庫中讀取圖像文件
Sub ReadFile()
Dim Stm As New ADODB.Stream
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCnn As String
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & _
App.Path & "\DB1.mdb"
Cnn.Open strCnn
rs.Open "SELECT IMAGE FROM TABLE1 WHERE ID = 18", Cnn, adOpenKeyset, adLockReadOnly
'保存到文件
With Stm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write rs("IMAGE")
.SaveToFile App.Path + "\Image2.bmp"
End With
'顯示圖片
Picture1.Picture = LoadPicture(App.Path + "\Image2.bmp")
rs.Close
Stm.Close
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub