如何在 SQL Server 2008 中存储图像 blob 数据?
How to store image blob data in SQL Server 2008?
我需要将图像 blob 数据存储在 table 中。我知道在数据库 table 中以 blob 格式存储图像不是最佳做法。但这样做是客户的要求。我正在使用 ColdFusion 10 和 SQL Server 2008。我使用此代码段将图像 blob 数据插入 SQL 服务器。
<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但是找不到任何解决方案。
我终于解决了这个问题。我做过的两件事是,
我已经为数据源启用了 BLOB 设置。
我终于用到了这个查询
<cfquery datasource="localdsn">
INSERT INTO imtbl(image)
VALUES (
<cfqueryparam
cfsqltype="cf_sql_blob"
value="#fileReadBinary('C:\inetpub\wwwroot\a.jpg')#">
)
</cfquery>
我需要将图像 blob 数据存储在 table 中。我知道在数据库 table 中以 blob 格式存储图像不是最佳做法。但这样做是客户的要求。我正在使用 ColdFusion 10 和 SQL Server 2008。我使用此代码段将图像 blob 数据插入 SQL 服务器。
<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但是找不到任何解决方案。
我终于解决了这个问题。我做过的两件事是,
我已经为数据源启用了 BLOB 设置。
我终于用到了这个查询
<cfquery datasource="localdsn">
INSERT INTO imtbl(image)
VALUES (
<cfqueryparam
cfsqltype="cf_sql_blob"
value="#fileReadBinary('C:\inetpub\wwwroot\a.jpg')#">
)
</cfquery>