Tuesday, April 23, 2024
HomeWeb developmentThe right way to Get a Base64 Model of a File From...

The right way to Get a Base64 Model of a File From Command Line


Some time again I wrote an article on how one can Convert Picture to Information URI with JavaScript. It is a neat trick builders can use for any variety of causes. As a substitute of abusing canvas, nonetheless, why not merely get the base64 knowledge from command line?

You need to use base64 and pbcopy to transform a file to base64 and replica it to the clipboard:

# base64 will get knowledge, pbcopy copies to clipboard
base64 -i brand.jpeg | pbcopy

After getting the file knowledge copied in base64 format, the URL format to make use of the info is:

# knowledge:{mime-type};base64,{knowledge}
knowledge:picture/jpeg;base64,/9j/4AAQSkZJRgAB......

Whereas base64 knowledge and knowledge URIs do look cryptic, they’re helpful to keep away from making requests to different recordsdata. I take advantage of them when creating displays or once I cannot rely on a good web connection.

  • fetch API

    One of many worst stored secrets and techniques about AJAX on the internet is that the underlying API for it, XMLHttpRequest, wasn’t actually made for what we have been utilizing it for.  We have achieved properly to create elegant APIs round XHR however we all know we will do higher.  Our effort to…

  • 9 Mind-Blowing WebGL Demos

    As a lot as builders now detest Flash, we’re nonetheless taking part in a little bit of catch as much as natively duplicate the animation capabilities that Adobe’s outdated know-how offered us.  After all now we have canvas, an superior know-how, one which I highlighted 9 mind-blowing demos.  One other know-how accessible…


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments