【问题标题】:saving blob picture into database without storing to hd将 blob 图片保存到数据库而不存储到 hd
【发布时间】:2012-02-01 23:19:57
【问题描述】:

我在coldfusion中有一个base64图片字符串。

如何将此图像 blob 保存到数据库中而不存储到文件磁盘? 我的功能。

<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----数据库

有什么帮助吗?

【问题讨论】:

    标签: coldfusion blob


    【解决方案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#" />)
    

    【讨论】:

    • Ben 的建议是一个很好的建议,但我不确定您是否希望 cfimage 标记为您做一些工作,而不仅仅是读取二进制数据。如果你这样做,那么我的回答会有所帮助。
    【解决方案2】:
    ToBinary('#yourString#')
    

    计算 Base64 编码数据的二进制表示

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 2012-08-10
      • 2011-07-23
      • 1970-01-01
      • 2020-02-15
      • 2020-02-11
      • 2021-03-19
      • 1970-01-01
      • 2014-04-07
      相关资源
      最近更新 更多