Copy link to clipboard
Copied
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
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#">
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
It is a dataURL string
data:video/webm;base64,GkXfo0AgQoaBAUL3gQFCBQ ...
Copy link to clipboard
Copied
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#">
Copy link to clipboard
Copied
Thanks for the suggestion to not use ToBase64. Your removeChars/ToBinary approach works great!
Appreciate the help.
Don
Copy link to clipboard
Copied
Glad to hear. Have fun with the rest of it!
Copy link to clipboard
Copied
Ah, arguments.dataUrl is a base 64 string, right?
Copy link to clipboard
Copied
Yes and No. I believe pure Base64 string doesn't include the mime type part at the beginning "data:video/webm;base64," like a dataURL string does. If I dump the results of ToBase64, it strips this part out.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more