Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Looking at the MBtiles spec, the tile_data field of the tiles table is just a blob of a tile image.

With this information, I expected to be able to take a data URI, string it of everything except the base64 encoded string, and decode it for storage in the tile_data field.

For instance:

var dataURI = "data:image/jpeg;base64,[some_encoded_data]";
var unencodedBytes;
if (dataURI.split(',')[0].indexOf('base64') >= 0) {
    unencodedBytes = atob(image.split(',')[1]);
} else {
    unencodedBytes = unescape(dataURI.split(',')[1]);

At this point, my unencodedBytes variable should have raw jpeg image data, and as such, I should be able to insert it into a tile_data field, correct? Is there an additional step I need to take? The data looks like belongs there, based off my observations of other valid mbtiles files, however all the mbtiles viewers I try to view this either do not show the data, or say they cannot figure out what type of data it is (jpeg or png).

What am I doing wrong? This is all being run in javascript in a browser, and I am using WebSQL to create the mbtiles file, since it is (supposedly) compatible.

Thanks in advance

share|improve this question

MBTiles stores image data as binary blobs, since base64 encoded URLs are very inefficient and storing binary in SQLite is safe. It's not very clear from your code sample what your actual query looks like, so hard to debug at this point.

This is all being run in javascript in a browser, and I am using WebSQL to create the mbtiles file, since it is (supposedly) compatible.

Did you read this somewhere? While WebSQL can be backed by SQLite, it doesn't generate files in a specific manner and isn't supposedly or officially compatible.

share|improve this answer

SQLite stores blob data however you pass it in. So in your case, you are storing the decoded string representation of the original base64 encoded image data. You need to pass it in as binary to retrieve it properly. I am not a javascript expert, but it appears javascript has only recently obtained support for allocating memory arrays (due to WebGL?). You have to hunt around for conversions to and from base64/arraybuffers.

Take a look at this:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.