开发者

Display the BLOB objects in Coldfusion

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])>                  
         <t开发者_开发百科d>#CharsetEncode(UpdateResult[ColName][UpdateResult.CurrentRow], "ISO- 8859-1" ) #</td> 
        <cfelse>
          <td>#UpdateResult[ColName][UpdateResult.CurrentRow]#</td> 
       </cfif> 
      </cfloop>  
    </tr>
 </cfloop>`


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜