You must specify a content-type. Aborting request.

222 views
Skip to first unread message

Tim Vanderlois

unread,
Jun 17, 2015, 9:51:16 AM6/17/15
to taffy...@googlegroups.com
I'm attempting to follow the example at http://milanchandnacf.blogspot.com/2012/06/coldfusion-html-to-pdf-service-rest-api.html

Getting error: "You must specify a content-type. Aborting request." ... found in api.cfc line 633ish

Guessing the consuming cfhttp needs some other header param???

Consuming Code:

<cffile action="read" file="/var/www/tvanderl/test/htmlToPdf/sample.cfm" variable="html" >

<cfhttp url="99.99.99.99/tvanderl/test/htmlToPdf/api/index.cfm/pdf/" result="test" method="post">
<cfhttpparam type="header" name="accept" value="application/xml" >
  <cfhttpparam type="header" name="Content-Type" value="text/html;charset=UTF-8" >
<cfhttpparam type="body" value="#html#" >
</cfhttp>

API Code api/resources/pdf.cfc:

<cfcomponent extends="taffy.core.resource" taffy:uri="/pdf/" >

<cffunction name="post" access="remote" returntype="binary" output="false" produces="application/xml">
<cfargument name="data" type="string" >

 <cfset pdffile = "" >
 <cfdocument format="PDF" overwrite="yes" name="pdffile" >
  <cfoutput>#data#</cfoutput>
 </cfdocument>

  <cfreturn #pdffile#>
</cffunction>

</cfcomponent>

Adam Tuttle

unread,
Jun 17, 2015, 11:49:52 AM6/17/15
to taffy...@googlegroups.com
Hi Tim,

You've got a couple of missteps in your code, here.

For starters, your URI should probably not end with a slash: taffy:uri="/pdf" -- though I doubt this is causing you any problems at the moment.

Then, you have to send data in a format that Taffy can handle. Out of the box, that means just JSON. You could very easily add a "text/html" deserializer that takes the body input and puts it into the "data" argument you provide... But let's step back for a second and look at how input data is handled in the usual (JSON) scenario.

A POST is done with a body something like: { "foo": 1, "bar": 2 }

Taffy will automatically deserialize this and then map those two body arguments, foo and bar, to the resource method's arguments:

function post( foo, bar ){}

Now, let's look at your method:

function post( data ){...}

Taffy needs to know how to get from the request's body to { "data": ? }. That's what you can do in your deserializer.

I'm just writing this in my email, not testing as I go, so it may have some bugs, but here's a guess at the deserializer you need to write:

component extends="taffy.core.baseDeserializer" {

    function getFromHTML( body ) output="false" taffy:mime="text/html" {
        return { data: body };
    }

}

You can get more info on writing a custom Deserializer here.

So that should get your input into the resource method, but sending a file back to the client is not quite as easy as you've written. Instead of the usual return representationOf( data here ); method of sending response data back to the client, you'll want to use return streamFile(...);

Hope that helps!

Adam

--
You received this message because you are subscribed to the Google Groups "Taffy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to taffy-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages