使用Coldfusion存储文件(可以是.txt,.doc,.docx)时,我希望能够检索这些文件。我已经搜寻了一段时间,但似乎找不到答案。
基本上:如何检索可以是多种类型的文件扩展名的Blob(SQL Server 2008中的varbinary(MAX)),然后提供下载?
这是我的上传/下载代码,其中有我的下载文件受阻:
<!--- <form action="resume.cfm" method="post" enctype="multipart/form-data">
Select File: <input type="file" name="upload" />
<input type="submit" value="Upload File" />
</form>
<cfif structKeyExists(form, "upload")>
<cfquery datasource="#application.dsn.recAppTest#" name="resume">
INSERT INTO resume (resume)
VALUES(
<cfqueryparam cfsqltype="cf_sql_blob" value="#FileReadBinary(FORM.upload)#">
)
</cfquery>
</cfif> --->
<cfoutput>
<cfquery datasource="#application.dsn.recAppTest#" name="resume">
SELECT * FROM resume
</cfquery>
<cfdump var="#resume#" />
</cfoutput>
<cfheader name="Content-Disposition" value="attachment; filename=""> <!--- what goes here if I don't know the incoming extension?? --->
<cfcontent type="text/plain, application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
我什至不确定这是否可行(我希望是这样),但是如果不能,一种解决方法是(在上传时)抓住文件扩展名,然后将其转换为数字(varbinary)并将其存储为单独的字段?
正如@imthepitts所说,您在接收文档时需要存储文件名。<cfcontent>
支持一种var
属性,该属性使您可以通过一次操作将文件发送回:
<cfcontent type="application/...." var="#resume.resume#" />
确保检查代码是否在适当的Web服务器上正常工作。JRun内置服务器发送回的头和响应与IIS或Apache会稍有不同。
如果需要支持IE的早期版本,请对其进行测试。我遇到的问题是标题的顺序有所不同(即使不应该如此)。我不得不使用基础的HTTPServletResponse方法。尽管很旧,但此链接很有用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句