使用 Coldfusion 从 Postgres 存储和检索图像
我正在将数据库从 mssql express 2005 迁移到 postgresql 9.0。 在 mssql 中,列是图像类型,在 postgresql 中,我使用 bytea 类型。
<cffile
action="readbinary"
file="#ExpandPath('./uploads/')##theLogo.SERVERFILE#"
variable="myLogo">
<cfquery
name="saveLogo"
datasource="#SESSION.DSN#">
UPDATE bright.group SET LOGO = <cfqueryparam
cfsqltype="cf_sql_blob"
value="#myLogo#">
</cfquery>
当我保存时,上面的代码片段似乎有效,但是当我尝试使用下面的代码片段显示图像时,我什么也没得到。
<cfquery
datasource="#SESSION.dsn#"
name="image">
SELECT LOGO
FROM bright.group
WHERE groupid=#URL.groupid#
</cfquery>
<cfcontent variable="#image.LOGO#" type="image/png">
这适用于 mssql,但不适用于 postgres。
任何帮助/指导将不胜感激。 谢谢
I am in the process of migrating a database from mssql express 2005 to postgresql 9.0.
In mssql the column is an image type and in postgresql i'm using the bytea type.
<cffile
action="readbinary"
file="#ExpandPath('./uploads/')##theLogo.SERVERFILE#"
variable="myLogo">
<cfquery
name="saveLogo"
datasource="#SESSION.DSN#">
UPDATE bright.group SET LOGO = <cfqueryparam
cfsqltype="cf_sql_blob"
value="#myLogo#">
</cfquery>
The snippet above seems to work when I do a save but when I try to display the image with the snippet below I get nothing.
<cfquery
datasource="#SESSION.dsn#"
name="image">
SELECT LOGO
FROM bright.group
WHERE groupid=#URL.groupid#
</cfquery>
<cfcontent variable="#image.LOGO#" type="image/png">
This works on mssql but not on postgres.
Any help/direction would be greatly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以进行适当的重构并放弃将图像保存在数据库中吗?
使用二进制文件的文件系统和数据库来保存这些资源的路径。它将加快您的应用程序并使未来的迁移变得更加容易。
Could you do a proper refactoring and abandon saving images in the database?
Use the file system for binary files and the database to keep the paths to these resources. It's going to speed up your application and make any future migration much easier.
不知道太多来解释真正的机制,但这就是我发现的。
图像的存储方式不同。我在十六进制查看器中打开返回的图像。 postgresql 文本从第二个字节到末尾与 mssql 十六进制值匹配。
我尝试了一切方法来转换 postgresql 输出,但没有成功。第一个字节不同并没有帮助。
最后我将数据类型从 bytea 更改为 text 并保存编码的二进制文件。
希望有人觉得这有帮助。
Don't know much to explain the real mechanics but this is what I found out.
The image gets stored differently. I opened up the returned images in a hex viewer. The postgresql text matched the mssql hex values from the 2nd byte to the end.
I tried everything to convert the postgresql output to no avail. It didn't help that the first byte was different.
In the end I changed the data type from bytea to text and saved the encoded binary file instead.
Hope someone finds this helpful.