Skip to main content
Participant
April 15, 2014
Answered

ToBase64 with webm

  • April 15, 2014
  • 1 reply
  • 693 views

I'm trying to write a webm dataURL to a file using CFFILE.  Do I use ToBase64 first and pass it to CFFILE output? I tried this but the resulting video file won't play.  It has a file size but won't play.

I'm using Ajax to send the dataURL string to my ctc function.  How do I write a video to a file? The dataURL mime type is webm.

<cfset vid64=#ToBase64(arguments.dataUrl)#>

<cffile action="write" output="#vid64#" file="#videopath#\#videoString#">

Thanks

Don

This topic has been closed for replies.
Correct answer BKBK

It is a dataURL string

data:video/webm;base64,GkXfo0AgQoaBAUL3gQFCBQ ...


Aha! Then, I am assuming that the part you want, the base64 part, is GkXfo0....That is, without the first 23 characters. If so, it is unnecessary to convert it to base 64! You could just convert to binary like this,

<cfset base64Webm = removeChars(arguments.dataUrl, 1, 23)>

<cfset binaryWebm=toBinary(base64Webm)

<cffile action="write" output="#binaryWebm#" file="#videopath#\#videoString#">

1 reply

BKBK
Community Expert
Community Expert
April 16, 2014

The nature of dataURL is unclear. If, as its name says, it is a URL, then what your code is doing is simply writing a string to file.

So, how is the data coming in? In other words, what is dataURL?

Participant
April 16, 2014

DataURL is a standard HTML5 way of viewing images/videos, etc. via data.  Like a base64 blob.

http://en.wikipedia.org/wiki/Data_URI_scheme

You can take a photo on a phone, read it as a dataURL and send it to the server via JSON.

CF gets the text version of it, reads it as base64 then writes it to database or file

<cfset picImage=ImageReadBase64(#arguments.imageDataUrl#)>

<cfimage action="write" source="#picImage#" destination="#path#\#fileString#" overwrite="true">

Issue I'm having is that ImageReadBase64 works great for images. However, ToBase64 is not working well will a dataUrl on video/webm mime type. 

Hope this provides better information.

Thanks,

Don

BKBK
Community Expert
Community Expert
April 16, 2014

Sorry, I could have been clearer. I have read up a bit on Data URI. What I am asking is, what is the nature of the parameter arguments.dataUrl? A URL? A base64 string? An ordinary string? A binary?