A reader asked for help using Brightcove's API to upload a video using ColdFusion. While I do not plan on writing a full wrapper, or going into great detail, I thought a quick blog post on what he tried, and why it failed, could help others who plan on using the service.
Let's first look at his original code and a description of the problem he had.
2 timeout="600" result="resultVar" multipart="true">
3
4 <cfhttpparam type="file" name="file" file="c:\com\brightcove\AT_T_test.mp4" />
5
6 <cfset jsonRequest = '{"method": "create_video", "params":
7 {"video": {"name": "test", "shortDescription": "test"},"token":
8 "blahblahblah.."}}'>
9
10 <cfhttpparam type="url" name="json" value="#jsonRequest#">
11
12 <cfhttpparam type="body" name="json" value="#jsonRequest#">
13
14 </cfhttp>
Even without knowing the API, you can see that it makes use of JSON to pass parameters about the upload. This code won't work at all because you can't mix a httpparam of type body with type file. The API docs though seemed to imply you needed to send the JSON values as the body. I first attempted to simply save the JSON to the file system and send it as a second file. This didn't work. I then dig a bit of digging and discovered this forum post by the Brightcove team: http://forum.brightcove.com/brgh/board/message?board.id=Developer_2&message.id=85
It pointed out that the JSON data could be sent as a form field, and it showed that my reader was missing a bit of data as well. Oddly - another issue was the order of the HTTP params. I can't image why this makes a difference, but if the JSON data isn't the first httpparam, then nothing else works. The final, working code, is below. Note - I removed his API key so you can't run this as is.
2 "CFHTTP create","shortDescription": "test video"},"token":
3 "falkeapikey"},"filename":
4 "actual2.mp4","maxsize":640000}'>
5
6 <cfhttp url="http://api.brightcove.com/services/post" method="post"
7 timeout="600" result="resultVar" multipart="true">
8
9 <cfhttpparam type="formfield" name="json" value="#json#">
10 <cfhttpparam type="file" name="actual2.mp4"
11 file="/Users/ray/Documents/workspace/youtubecfc/unittests/actual2.mp4"
12 />
13 </cfhttp>
14
15 <cfdump var="#resultvar#">
Anyway - I don't have time to dig into the Brightcove API more, but I'm sure someone out there could whip up a quick component.
Comment 1 written by Brian Deitte on 1 December 2009, at 12:46 PM
Comment 2 written by Bill Davidson on 1 December 2009, at 10:51 PM
I do plan on writing a "full" API wrapper. I already have some of the read API methods done from awhile ago. The write API uses a different endpoint and seems to be more picky. If the client allows, I'll try to open source the API wrapper.
Thanks again to Ray for helping me out on this!
Comment 3 written by Brian Deitte on 2 December 2009, at 8:58 AM
Comment 4 written by William Haun on 3 December 2009, at 10:35 AM
I found a way in the Flash player to read the metadata once the video is loaded (using a AS3 property called videocodecid) but I'd rather stop the video creator from uploading the poorly encoded MP4 at all.
In regards to your code above, it would be great for CF to check the MP4's codec before uploading it to BrightCove (after all their Flash video player can only play H.264 too).
Any ideas?!
Comment 5 written by Raymond Camden on 3 December 2009, at 10:44 AM
If you can find a good Java wrapper (google returned this one: https://contributions.coremedia.com/isobox4j - but no idea how good it is) then you can use it via CF.
Comment 6 written by Brian Deitte on 3 December 2009, at 10:49 AM
Comment 7 written by Bill Davidson on 14 December 2009, at 1:03 PM
Version 1.0 of my Brightcove SDK is done... Waiting for approval on Riaforge and it will hopefully live there.
Comment 8 written by Raymond Camden on 14 December 2009, at 1:46 PM
Comment 9 written by Brian Deitte on 14 December 2009, at 2:02 PM
Comment 10 written by Bill Davidson on 14 December 2009, at 2:22 PM
Brian - cool!
It's up now at: http://cfBCove.riaforge.org/
Comment 11 written by Brian Deitte on 14 December 2009, at 8:51 PM
There may be a blog post on it somewhere on the site, as that often happens for things like this. I'll post a link here if there is one.
Comment 12 written by Brian Deitte on 15 December 2009, at 6:22 AM
Comment 13 written by Bill Davidson on 15 December 2009, at 9:34 PM
[Add Comment] [Subscribe to Comments]