This is in reference to my question - Attach content of HTML5 WebSQL databse to email using javascript
I have an HTML5 app that will run in Chrome browser. I need to export the data stored locally in the Web SQL DB and put it into a csv or txt file.
I need to do this in the browser. Server side code is not an option. How can this be done usng javascript? Thanks
EDIT: I found that one way of achieving this is through Data URI. So I have my result set from select query in the results object. How do I encode it to base 64 format?
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>Found rows: " + len + "</p>";
document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++){
alert(results.rows.item(i).log );
}
}, null);
});
//Encode the results object to base64
/* How can we do this? */
<a download="example.csv" href="data:application/csv;charset=utf-8, <<base64_encoded_data>>">Test</a>