Jonas Bolin
Jonas Bolin

Reputation: 616

Convert audio file to base64

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?

Upvotes: 4

Views: 3695

Answers (1)

Taner Topal
Taner Topal

Reputation: 921

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.

Upvotes: 1

Related Questions