2012-01-31 117 views
1

我在Coldfusion中有一個base64圖片字符串。將blob圖片保存到數據庫而不存儲到hd

如何將此圖像blob保存到數據庫中而不存儲到filedisk? 我的功能。

<cfset base64string="base64picturestring"> 
<cfimage source="#ImageReadBase64("data:image/png;base64,#base64string#")#" 
destination="c:\picture.png" action="write" overwrite="true"> 
<cffile action="readbinary" file="c:\picture.png" variable="ImageData"/> 

INSERT INTO imagedb (imageblob) 
VALUES (<cfqueryparam cfsqltype="cf_sql_blob" value="#ImageData#" />) 

但我不想將圖像保存在硬盤上。 我需要這個。

的base64 ---- ---- imageblob數據庫

任何幫助嗎?

回答

1

你可以使用內存中的文件系統:

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSe9cbe5cf462523a0-70e2363b121825b20e7-8000.html#WSe9cbe5cf462523a0-540771bc12182683461-8000

<cfset base64string="base64picturestring"> 
<cfimage source="#ImageReadBase64("data:image/png;base64,#base64string#")#" 
destination="ram://src/picture.png" action="write" overwrite="true"> 
<cffile action="readbinary" file="ram://src/picture.png" variable="ImageData"/> 
<cffile action="delete" source = "ram://src/picture.png"> 

INSERT INTO imagedb (imageblob) 
VALUES (<cfqueryparam cfsqltype="cf_sql_blob" value="#ImageData#" />) 
+0

Ben的建議是一個很好的,但我沒不要確定您是否期望cfimage標籤爲您做一些工作,而不是簡單地讀取二進制數據。如果你這樣做,那麼我的回答會有幫助。 – 2012-01-31 19:31:34

+0

我會檢查這個,謝謝 – user1181110 2012-01-31 19:39:26

0
ToBinary('#yourString#') 

計算Base64編碼的數據

的二進制表示