0

I am reading images from a db, each image is composed by small images (3 or more). So, I am trying to printout with a loop:

    res.writeHead(200, {'content-type':'text/html'});

    var sqlite3 = require('sqlite3').verbose();
    var db = new sqlite3.Database('./routes/mytiles.mbtiles');
    var sql = "SELECT images.tile_data FROM images, map WHERE images.tile_id = map.tile_id AND map.zoom_level = 14 AND map.tile_column = 14125";    
    db.each(sql, function(err, row) {
            console.log(row.tile_data);
           res.write('<img src="data:image/jpg;base64,'+row.tile_data+'">&nbsp;');
    }); 
    db.close(); 

But, in the browser I only got ascii code (just like when you open a image file with a text editor). How can I solve his?

Thanks

  • Just a note, I'd rather have the image paths be stored in the database and the images stored on the server files, that way when getting images you just need to get the path from the database as a string. – Spencer Wieczorek Jul 29 '15 at 15:41
  • totally agree... but this is the way it is built.. cant do anything to change that.. is not in my hands... – Patricio Carvajal H. Jul 29 '15 at 15:45
  • Shouldn't `image/jng` be more `image/png` or something else, not aware of `jnp` being a common image extension. – GillesC Jul 29 '15 at 15:45
  • Also aren't you missing the `base64` bit too. See http://stackoverflow.com/questions/1207190/embedding-base64-images – GillesC Jul 29 '15 at 15:46
  • I have updated the code... I have typed "jpg" wrong.. adedd base64. but still get the ascii code in browser. – Patricio Carvajal H. Jul 29 '15 at 19:55

0 Answers0