Solved

Coldfusion Error: The toString method was not found

Posted on 2016-08-06
5
49 Views
Last Modified: 2016-08-06
Hello experts
I recently intalled Coldfusion 2016 Developer edition and while i was  trying to use the toString function as i was doing until now with CF9 i got the error: The toString method was not found
Any help?
error line:
 <cfset utf8Response = response.fileContent.toString("UTF8")>
0
Comment
Question by:Panos
  • 3
  • 2
5 Comments
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 500 total points
Comment Utility
Edit - Added code

Sounds like response.fileContent contains a different type of object than the code was expecting? If you dump it, what does it actually contain - string, binary, null ...?

Type: <cfdump var="#response.fileContent.getClass().getName()#">
Value: <cfdump var="#response.fileContent#">

Side note, why was the CF9 code using the java method toString("UTF8")? Normally the fileContent already is a string (or sometimes binary)?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
I'd guess it's returning a byte array. That type of object doesn't have a ToString() method, hence the error.  Test whether the result IsBinary(). If yes, use charsetEncode() to convert it to a string:

<!--- deliberately force response to be binary --->
 <cfhttp url="http://api.openweathermap.org/data/2.5/find?=San+Fransico&mode=json"
          method="GET"
          getAsBinary="yes"
          result="response" / >
 
 <cfif isBinary(response.filecontent)>
        <cfset responseString = charsetEncode(response.filecontent, "utf-8")>
 <cfelse>
        <cfset responseString = response.filecontent>
 </cfif>

  DEBUG
 <cfoutput>
     <br>class = #response.filecontent.getClass().name#
     <br>value = #responseString#
 </cfoutput>

Open in new window

0
 
LVL 2

Author Comment

by:Panos
Comment Utility
Hi agx.
Thank you very much for your help.
It is really a binary response.
I don't know how i was confused with CF9.
The problem is fixed.
0
 
LVL 2

Author Closing Comment

by:Panos
Comment Utility
Thank you again
regards Panos
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
>> don't know how i was confused with CF9

Well if the exact same code and url work w/CF9, but not CF2016, it's entirely possible Adobe changed something.  Wouldn't be the first time.  Anyway, glad it helped.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now