mardi 3 mars 2015

base64 image is sometimes broken

I need to send images in an email. I am using nodejs on server side. I am doing this in my code as follows:



  1. read image file using fs.readFile

  2. encode to base64 (i.e. new Buffer(data, "binary").toString("base64"))

  3. set image src to 'data:image/png;base64,' + output of step 2.

  4. print output html to console.


I tested my function out a couple of times, saved the output html for each run to file and tested using Chrome. The problem is that sometimes the image shows up correctly and sometimes it shows up as broken in the browser. How can I fix this?


Aucun commentaire:

Enregistrer un commentaire