【发布时间】:2015-04-02 18:46:51
【问题描述】:
我需要将图像 blob 数据存储在表中。我知道在数据库表中以 blob 格式存储图像不是最佳做法。但这样做是客户的要求。我正在使用 ColdFusion 10 和 SQL Server 2008。我已经使用这个 sn-p 在 SQL server 中插入图像 blob 数据。
<cfimage action="read" name="imdata" source="C:\inetpub\wwwroot\a.jpg" >
<cfquery datasource="localdsn">
INSERT INTO imtbl(image)
VALUES #imageGetBlob(imdata)#
</cfquery>
但它正在抛出错误
ByteArray objects cannot be converted to strings.
我也尝试过使用#toString(imageGetBlob(imdata))# 仍然没有成功。
我已经通过https://forums.adobe.com/thread/60629但是找不到任何解决方案。
【问题讨论】:
-
您是否在 ColdFusion 数据源上启用了 BLOB 设置?
-
您是否尝试过使用 cfqueryparam 参数化博客?像
<cfqueryparam cfsqltype="cf_sql_blob" value="#imageGetBlob(imdata)#">这样的东西可能有助于揭露正在发生的事情。 -
@Miguel-F:是的,我已启用它,但仍然无法正常工作,
-
差不多。
FileReadBinary()需要一个文件路径。您正在传递一个图像变量。去掉cfimage并在你的cfqueryparam 中使用FileReadBinary("C:\inetpub\wwwroot\a.jpg")。此外,您显然需要在VALUES (...)子句中加上括号。 -
我会添加以下通知:如果您在SQL Server中使用图像类型(将在以后的版本中删除),请将其替换为varbinary(max) - VarBinary vs Image SQL Server数据类型存储二进制数据?
标签: sql-server sql-server-2008 coldfusion coldfusion-10