我需要将图像 blob 数据存储在表中。我知道在数据库表中存储 blob 格式的图像不是最佳实践。但这样做是客户的要求。我正在使用 ColdFusion 10 和 SQL Server 2008。我使用此代码片段在 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 对象无法转换为字符串。
我也尝试过使用#toString(imageGetBlob(imdata))#
仍然没有成功。
我已经浏览过https://forums.adobe.com/thread/60629但找不到任何解决办法。
最佳答案
终于我解决了这个问题。我做过的两件事是,
我已为数据源启用 BLOB 设置。
我终于使用了这个查询
<cfquery datasource="localdsn">
INSERT INTO imtbl(image)
VALUES (
<cfqueryparam
cfsqltype="cf_sql_blob"
value="#fileReadBinary('C:\inetpub\wwwroot\a.jpg')#">
)
</cfquery>
关于sql-server - 如何在 SQL Server 2008 中存储图像 blob 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28301177/