I have been trying to load PDF files into Oracle using Coldfusion and download
them again and it seems the data is corrupt (thatâs the error message I get
when I download it). The files seem to load properly (as byte array) it's when
I try to doanload them is when I get the corrupted data error. Any help on what
is going on/what the problem is? Here is my code/table:
CREATE TABLE TBL (
USERID NUMBER(10),
DEPARTDOC BLOB
)
<!--- 1.cfm --->
<form action="2.cfm" method="POST" enctype="multipart/form-data">
File Name: <input name="FileName" type="file">
<input name="Submit" type="submit" value="Save">
</form>
<!--- 2.cfm --->
<cfset Directory_Path = GetDirectoryFromPath(GetTemplatePath())>
<cfif IsDefined("Form.Submit") AND Trim(form.FileName) NEQ "">
<cftry>
<cffile action="upload"
filefield="form.FileName"
destination="#Directory_Path#"
nameconflict="makeunique"
accept="application/iso-8859-1, application/pdf">
<cffile
action = "readbinary"
file = "#Directory_Path##cffile.serverFile#"
variable="file_blob">
<cfquery name="upload" datasource="dsn">
INSERT INTO TBL (
USERID, DEPARTDOC)
VALUES (
3,
<cfqueryparam
value="#file_blob#"
cfsqltype="cf_sql_blob">
)
</cfquery>
<cfcatch type="application">
Error...
</cfcatch>
</cftry>
</cfif>
<!--- 3.cfm --->
<cfheader
name="content-disposition"
value="attachment; filename=myFile.pdf">
<cfquery name="q" datasource="dsn">
select DEPARTDOC
from TBL
where userid = 2
</cfquery>
<cfcontent
type="application/iso-8859-1, application/pdf"
variable="#q.DEPARTDOC#">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive: http://www.houseoffusion.com/groups/sql/message.cfm/messageid:3248
Subscription: http://www.houseoffusion.com/groups/sql/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.6