Downloading file from url ColdFusion - coldfusion

Is it possible to download a pdf from given url and save it to a server using ColdFusion?
I am looking for a method similar to a file_put_contents() in php and I couldn't find anything in the Adobe documentation.
Thanks!

Yes, you can use the cfhttp tag to download a document from a URL and save it to a file:
Specifically, you'll do something like:
<cfhttp method="get" url="#fileURL#" path="#filePath#" file="#fileName#" />

Related

Coldfusion RESTful API, No Mapping Found error

This shouldn't be too hard to answer, but the discussions and documentation I've found can be rather unclear.
First of all, a little bit of information about my setup:
I'm on a hosted environment, and going through our ColdFusion admin group can be time-consuming. Therefore, I'm using the
restInitApplication function to register my RESTful web service.
My webroot folder (where my Application.cfm is located) is in
"E:\docs\wwwroot". I can only see, add, edit folders/files from
wwwroot down. I have no idea what's in "e:\docs". I believe that up
above where I cannot see there is another Application.cfm that sets
such things as the serverType (development, staging, or production),
that we (and other ColdFusion sites hosted on this server) use in
various places in our application code.
My pdfRestfulAPI.cfc (the component containing my webservice function) is in this folder,
"e:\docs\wwwroot\RESTservices". My component code looks like this:
<cfcomponent rest="true" >
<cffunction name="pdfconvert" access="remote" returntype="binary"
output="false" produces="application/xml" method="get" >
<cfargument name="sourceWebPageURL" type="string" >
<cfset pdfDoc = "" >
<cfdocument name="pdfDoc"
format="PDF"
src="#sourceWebPageURL#"
saveAsName="sample.pdf" >
</cfdocument>
<cfreturn #pdfDoc#>
</cffunction>
</cfcomponent>
The function itself is not an issue. It just converts a web page to pdf--pass a URL, get a PDF version of that web page. When I set it up as non-RESTful API (SOAP/xml) it works just fine.
In my Application.cfm, I am attempting to register my web service using the following code:
<cfset restInitApplication( getDirectoryFromPath(getCurrentTemplatePath())
& "RESTservices" ) >
This gives me a dir_path attribute of "E:\docs\wwwroot\RESTservices", which seems correct to me. I've omitted the optional mapping_name attribute. When the documentation says that this "can be anything", that is not helpful.
The error that I get in my Application.cfm reads:
coldfusion.rest.RestAppAdapter$InvalidApplicationException: No mapping
found for path E:\docs\wwwroot\RESTservices
Hopefully, I've laid out the details in such a way that anyone could try this out and let me know what I'm doing wrong.
Thanks, everyone!

COM.Allaire.ColdFusion.HTTPFailure

I'm working on a web app that is ran nightly to retrieve a large XML file from another server. We're using ColdFusion MX7. We run a CFHTTP GET with username, pass, and url. Then we write the field with a cffileaction write to our temp location. So that it can be parsed and sorted into a database. There are a few CFHTTP calls on the page cut one of them is failing. In the CFCatch I have the system email me the catch type and the message and I'm getting this.
COM.Allaire.ColdFusion.HTTPFailure
Connection Failure: Status code unavailable
This the call an write action as is (the credentials are right):
<cfhttp method="GET"
username="#uname#"
password="#pw#"
url="#url#"
resolveurl="yes"
throwonerror="yes">
</cfhttp>
<cffile action="write" file="#getdirectoryfrompath(GetCurrentTemplatePath())#\XML_FileName.xml" output="#cfhttp.fileContent#">
Is anyone familiar with his error?
As it turns out we were getting the Cert from the other groups 'test' server and then trying to using to get things from their production server. So Peter was right! If you run into this problem check out these links:
CFHTTP Over SSL
http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:48687

Integrating SendGrid’s SMTP API with CFMAIL

I am using SendGrid’s SMTP API (not WEB API) and am considering sending an email using cfmail. If I use cfmail to send the email, and want to use the X-SMTPAPI header somewhere, do you think that cfmail is a place to do that? Please clarify.
You would do this by adding a custom header, using the cfmailparam tag. As such:
<cfmailparam
name="X-SMTPAPI"
value="{\"category\":\"Cool Emails\"}">
In context of the cfmail tag it would be as follows.
<cfmail
from="you#example.com"
to="nick#sendgrid.com"
subject="I am using CF Mail to do this!">
<cfmailparam
name="X-SMTPAPI"
value="{\"category\":\"Cool Emails\"}">
Look at my awesome use of cfmail!
</cfmail>
More can be found in the Adobe Documentation
This is what worked for me.
The above suggestion threw errors.
<cfmailparam
name="X-SMTPAPI"
value='{"category":["Cool Emails"]}'>

Upload video to Brightcove through HTML form with Coldfusion

I want to upload a video from an HTML form directly to Brightcove. We run Coldfusion 9 on our servers.
I can find instructions on uploading the video to my local server like this:
<cffile action="upload" nameconflict="makeunique" filefield="form.video_file" destination="#upload_path#" result="uploaded_file">
... and instructions on uploading a video from my local server to Brightcove like this:
<cfhttp url="#variables.apiBaseUrl#" method="post" timeout="#variables.timeout#" result="resultVar" multipart="true">
<cfhttpparam type="formfield" name="json" VALUE = "#arguments.jsonArgs#">
<cfhttpparam type="file" name="#getFileFromPath(arguments.filename)#" file="#arguments.filename#"/>
</cfhttp>
But not from the HTML form directly to Brightcove.
Is this possible?
Thanks!
Nick
There are examples of how to upload directly from the browser to Brightcove in their JavaScript Media API Examples.
But, as the documentation notes, what you want to accomplish is not recommended for a few reasons:
Some browsers such as IE9 will prompt you to download the response rather than show it in the form because the browser doesn't know what to do with the mime type.
It's not good practice to expose an API token on the form, as noted in the examples' source code.
Client-side Media API calls are not recommended as a UGC upload solution because of the lack of security.
If you're finding that the process for uploading to your server then to Brightcove is taking too long, you'll probably want to build a queue system.
The user waits on the browser to upload to your server.
Your server stores the file somewhere temporarily and adds a task to a database table storing queued tasks.
The user sees that the video is "pending" while it's still enqueued.
A scheduled task periodically checks the queue table and uploads the tasks one at a time. Once a task is done, it updates the video to be "ready."
The user sees that the video is ready.

What is the coldfusion code to upload a file in amazon s3 api?

I am having a problem trying to figure out what is the proper coldfusion code to upload a simple file into amazon s3 api. Any help is much appreciated!!!
There is a good tutorial here. You'll need CF 9.0.1 however.
Prior to CF 9 you might be able to use this CFC that Barney Boisvert wrote.
Try this CFC: http://amazons3.riaforge.org/
Also, note that you may also access your objects via:
http://bucketname.s3.amazonaws.com/name-of-the-object (example)
<cfset s3bucket = "s3://yourbuketname/">
<cffile action="upload" filefield="filename" destination="#s3bucket#" nameconflict="makeunique" charset="utf-8" />