Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Coldfusion Error: The toString method was not found

Posted on 2016-08-06
5
Medium Priority
?
117 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 2000 total points
ID: 41745598
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 2000 total points
ID: 41745609
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
ID: 41745620
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
ID: 41745623
Thank you again
regards Panos
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41745634
>> 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 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