Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ToBase64 with webm

New Here ,
Apr 15, 2014 Apr 15, 2014

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

717
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 16, 2014 Apr 16, 2014

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#">

Translate
Community Expert ,
Apr 16, 2014 Apr 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2014 Apr 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2014 Apr 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2014 Apr 16, 2014

It is a dataURL string

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2014 Apr 16, 2014

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#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2014 Apr 17, 2014

Thanks for the suggestion to not use ToBase64.  Your removeChars/ToBinary approach works great!

Appreciate the help.

Don

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2014 Apr 17, 2014
LATEST

Glad to hear. Have fun with the rest of it!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2014 Apr 16, 2014

Ah, arguments.dataUrl is a base 64 string, right?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2014 Apr 16, 2014

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.



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources