Skip to main content
Inspiring
August 4, 2009
Question

Oracle Blob - store and retreive PDF

  • August 4, 2009
  • 2 replies
  • 3150 views

I google this a lot, but could only find examples for images.

I am having trouble retreiving blob and opening it in the browser as PDF. I get the message "The file is damaged and could not be repaired" message in Adobe Reader. Here is the code.

To store

<cffile action="upload" filefield="form.filename" destination="c:\developer\temp\" nameconflict="overwrite">
<cffile action="readbinary" file="c:\developer\temp\#cffile.serverfile#" variable="file_blob">
<cfquery datasource="oraped">
update ped_ack set ack_blob = <cfqueryparam value="#file_blob#" cfsqltype="cf_sql_blob">  where instfk = 28739
</cfquery>

To retreive

<cfquery datasource="oraped" name="blob">
select ack_blob from ped_ack where instfk = 28739
</cfquery>
<cfheader name="content-length" value="#ArrayLen(blob.ack_body)#" />
<cfheader name="Content-Disposition" value="inline;filename=somename.pdf">
<cfcontent variable="#blob.ack_body#" type="application/pdf">

Your help is appreciated,

kat_dev

    This topic has been closed for replies.

    2 replies

    kat_devAuthor
    Inspiring
    August 6, 2009

    Mack,

    Thanks for the suggestion

    but I still get the message "The file is damaged and could not be repaired" from acrobat read,

    I tried with a few other pdfs, but with no luck.

    kat_dev

    Participating Frequently
    August 6, 2009

    Use Content-Disposition: attachment as a header and save the file.

    The file needs to start with %PDF.

    Mack

    Inspiring
    August 5, 2009

    Hi,

    Try using the "file" attribute in your <cfcontent> tag and pass the absolute path/file_name.extension to it.

    HTH

    kat_devAuthor
    Inspiring
    August 5, 2009

    That totally defeats the purpose of using the blob and the database to store files. I want to store files in the database and not directly on the server.

    My problem is ,that though I stream the binary content of the PDF using the variable attribute in cfcontent tag, it doesn't stream it properly. I get an error in adobe reader.

    kat_dev

    Participating Frequently
    August 5, 2009

    Make sure that you have reset=true on your cfcontent tag otherwise

    previous output will not be removed before sending the PDF and even a

    line break before your PDF content will break the PDF.

    Mack