coldfusion如何将pdf文件保存在数据库中并在浏览器中获取 [英] coldfusion How to save pdf file in database and fetch it in browser

查看:77
本文介绍了coldfusion如何将pdf文件保存在数据库中并在浏览器中获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

插入MS-SQL 2008数据库

Insert to MS-SQL 2008 Database

<cffile action="READBINARY" file="#form.FileContents#" variable="binPDF">
<cfquery name="Uploaded" datasource="#cfbasedatasource#">
INSERT INTO UploadedFiles
    (
    AccountId,
    Filecontent
    )
VALUES
    (
    '#UrlAccountId#',
    <cfqueryparam value='#binPDF#' cfsqltype='cf_sql_blob'>
    )
</cfquery>

========================= 这是从数据库到浏览器的显示:

========================= This is Show from Database to browser:

<cfset binaryData = #cfGetfilecontentquery.Filecontent[1]#>
<cfheader name="Content-Disposition" value="inline; filename=testDocument.pdf">
<cfcontent variable="#binarydata#" type="application/pdf" reset="yes" />

但是我只能在浏览器中看到无法加载PDF文档"

But I can only see in browser "Fail to Load PDF Document"

推荐答案

您的代码原则上是正确的.确保CF管理员中的设置允许Blob数据-否则可能会在数据库中被截断.通常不允许驱动程序通过BLOB数据(默认情况下,DSN设置中不允许BLOB数据).如果启用它,您应该会很好.

Your code is correct in principle. Make sure that the settings in the CF admin allow for blob data - otherwise it may be truncated in the DB. It's pretty typical to not allow BLOB data through the driver (by default it is NOT allowed in the DSN settings). If you enable it you should be good.

我正在发布此答案,因此您可以根据评论(根据Leigh的建议)将其标记为正确. :)

I'm posting this answer so you can flag it as correct based on the comments (per Leigh's suggestion). :)

这篇关于coldfusion如何将pdf文件保存在数据库中并在浏览器中获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆