Reputation: 964
I have an image asset in the private
directory of my Meteor project, and I need to encode the image into a data URI.
I know that I load the file using Assets.getBinary
, but what's the best way to base64 encode that file?
Upvotes: 0
Views: 611
Reputation: 964
Meteor actually has a built-in base64 package, although it's not added by default.
Add the package by calling meteor add base64
.
Then a data URI can be created like this:
var binaryImage = Assets.getBinary('pdf-logo.png');
var dataURI = 'data:image/png;base64,' + Base64.encode(binaryImage);
Upvotes: 2