SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot moretea's Avatar
    Join Date
    Jun 2004
    Location
    Texas, USA
    Posts
    118
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question Retrieving binary objects from SQL Server 2005 with ColdFusion MX 6.1

    I thought I'd be clever and store binary attachments (mostly MS Office files) to the DB; it didn't take too long to figure out how to insert to the DB, but I am at a dead end when it comes to retrieving those binaries. I think being stuck at CF 6.1 may be the biggest issue here...

    I have been working mostly from posts to Ben Nadel's blog (link 1, link 2). Here's my (abortive) code to retrieve a binary:

    Code CFM:
    <cfparam name="URL.id_attach" type="numeric" default="0" />
    <cfparam name="URL.id_rpt" type="numeric" default="0" />
    <!--- Query for file record and pull back binary. --->
    <cfquery name="qBin" datasource="#DataSource#">
     SELECT
      a.id_attach,
      a.id_rpt,
      a.file_descr,
      a.file_binary
     FROM
      rpt_attach a
     WHERE
      a.id_attach =
       <cfqueryparam
        value="#URL.id_attach#"
        cfsqltype="cf_sql_integer"
        />
     AND
      a.id_rpt = 
       <cfqueryparam
        value="#URL.id_rpt#"
        cfsqltype="cf_sql_integer"
        />
    </cfquery>
    <cfheader 
    name="content-length" 
    value="#ArrayLen( qBin.file_binary )#" 
    /> 
    <cfheader 
    name="content-disposition" 
    value="attachment; filename=#qBin.file_descr#.doc" 
    /> 
    <cfcontent 
    type="application/*" 
    variable="#qBin.file_binary#" 
    />
    The sticking point seems to be that the query returns a byte array, and I can't figure how to get CF 6.1 to stream that to the browser. Any ideas? TIA!

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think being stuck at CF 6.1 may be the biggest issue here...
    Yes, but I am certain it is possible with 6.1.

    IIRC the cfcontent "variable" attribute didn't get introduced until MX7. So try using the ToString(..) function as suggested in the comments here:
    http://weblogs.macromedia.com/cantre...coldfusio.html


    <cfcontent type="application/theCorrectTypeHere">
    <cfoutput>#ToString(qBin.file_binary)#</cfoutput>


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •