tags:

views:

417

answers:

2

I have a query which retrieves the data from Oracle DB. The table which I am retrieving contains one BLOB type column. When I tried to output it as

<cfoutput>#query.blobColumn#</cfoutput>

Its giving me the error "ByteArray objects cannot be converted to strings". I tried using

<cfoutput>#ToString(query.blobColumn)#</cfoutput>

Then it worked, but I am getting the content as "��t�".

Is there any way we can display some text of the blob(XML file) and if user clicks on it, we can display/download the full content of it?

This is the Code i am using

<cfloop query="UpdateResult">  
  <tr id="dataRow">  
     <cfloop index="ColName" `list="#UpdateResult.ColumnList#">  
       <cfif isBinary(UpdateResult[ColName[UpdateResult.CurrentRow])>                  
         <td>#CharsetEncode(UpdateResult[ColName][UpdateResult.CurrentRow], "ISO- 8859-1" ) #</td> 
        <cfelse>
          <td>#UpdateResult[ColName][UpdateResult.CurrentRow]#</td> 
       </cfif> 
      </cfloop>  
    </tr>
 </cfloop>`
+2  A: 

You might try using the CharsetEncode() function.

<cfoutput>#CharsetEncode( query.blobCoulmn, "us-ascii" )#</cfoutput>

From the documentation:

Adobe recommends that you use this function, and not the ToString function, to convert binary data to strings in all new applications.

It supports many character sets, us-ascii is only used as an example. Hope this helps!

mwc
Well, I am using a common code to display all the blob Types and String Types using the cfloop. When I got the Column which is of not BLOB Type Then Got "Parameter 1 of the CharsetEncode function, which is now '', must be a valid binary object"So Is there anyway we can Identify which type it is and if it BLOB type only then we will use CharsetEncode()?
CFUser
I take it you cannot refer to them as "query.blobColumn", "query.stringColumn", etc? Without seeing the code, the best I can offer is the 'isBinary()' function. It may do what you're asking.
mwc
Thanks mwc, It worked fine
CFUser
HI,I am still getting the Same Problem. Below is my code. Can you please suggest <cfloop query="UpdateResult"> <tr id="dataRow"> <cfloop index="ColName" list="#UpdateResult.ColumnList#"> <cfif isBinary(UpdateResult[ColName[UpdateResult.CurrentRow])> <td>#CharsetEncode(UpdateResult[ColName][UpdateResult.CurrentRow], "ISO- 8859-1" ) #</td> <cfelse> <td>#UpdateResult[ColName][UpdateResult.CurrentRow]#</td> </cfif> </cfloop> </tr></cfloop>I Tried all Encodings.. still its saem Problem :(
CFUser
I'm not sure what else to suggest. Ben Doom's suggestion of using a CLOB column instead of BLOB is a good one, perhaps you can try that. XML is text and thus should be stored in a Character Large OBject (CLOB) rather than a BLOB.
mwc
But Unfortunatly, I am getting these Resultset from other Application DB. So I cannot change the DataTypes :(
CFUser
There isn't much more I can think of to try. The `BinaryEncode()` converts a binary object into a string of hex values. Perhaps you could do something with that string. There must be a better solution! Sorry I couldn't be of more help.
mwc
+2  A: 

If the BLOB is binary data, then displaying it as a string won't work. Look into using CFCONTENT to deliver data in binary format. For the end user to receive it properly, you'll probably need to specify an appropriate MIME type.

Ben Doom
Hi Ben, My BLOB is a XML data
CFUser
While you can use a BLOB for XML (hey! everthing is binary!) most people would use an XMLtext, text, ntext, CLOB, or similar field. BLOB stands for Binary Long OBject.
Ben Doom
I certainly would use CLOB for XML data.
Al Everett