3

Im building a Phonegap application for a friend where I intend to let people record audio on their phone, save it to the browser's localstorage and then upload it later.

AFAIK, you can't store binary files in localstorage, so Im trying to convert this file to base64, but so far I cant get it to work the way I want it to.

var file = document.getElementById('audioinput').files[0];
var url = window.URL.createObjectURL(file);
encodedAudio = windows.btoa(url);

All this does is encoding the link to the blob where the file is temporarily stored. How do I encode the actual audio file?

Jonas Bolin
  • 606
  • 1
  • 11
  • 28
  • I can just imagine the size of the data... poor local storage... – VisioN Sep 01 '13 at 17:41
  • 1
    Save it to browser local storage? :O Please buddy, say the phone's local storage. Even the audio websites such as soundcloud use the phone's local storage to record the audio, name it! And upload it from there. You might want to read the phone's API to create the audio and then upload it from there by selecting it. – Afzaal Ahmad Zeeshan Sep 01 '13 at 17:48
  • @VisioN true :) it's mostly short snippets so should be fine (hopefully :)) – Jonas Bolin Sep 01 '13 at 17:52
  • 1
    Consider look how it got solved before: [html5-local-storage-of-audio-element-source-is-it-possible](http://stackoverflow.com/questions/1612116/html5-local-storage-of-audio-element-source-is-it-possible) – JohnnyJS Sep 01 '13 at 17:53
  • http://stackoverflow.com/questions/31161897/converting-audio-file-to-base64-using-javascript – zloctb Aug 03 '16 at 07:55

1 Answers1

1

If I am right the localstorage size is usually limit to something like 5MB. I'd recommend to use the Cordova File API http://docs.phonegap.com/en/3.0.0/cordova_file_file.md.html#File

I am not sure what kind of App your building but if you use the localstorage with 5MB and record with 128kb/s its like 40sec.

Taner Topal
  • 921
  • 8
  • 14