You are not logged in.

#1 2019-09-12 10:56:07

Registered: 2019-05-07
Posts: 312

Create Data Uri from a file in bash

I thought this was a neat command. I wouldnt recommend using it on a large file though, will output massive amounts of characters on your terminal. Small text files seem to be ok.
Ive used this for my resume and then shortened the 4000 plus character uri with

You can do something like $ dataurl myfile > myfile.txt if you dont want to output to screen.

# Create a data URL from a file
function dataurl() {
	local mimeType=$(file -b --mime-type "$1");
	if [[ $mimeType == text/* ]]; then
	echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"

Last edited by clusterF (2019-09-12 10:58:24)

"Common sense is like deodorant, those who need it the most never use it."

git: clusterF


Board footer

Powered by FluxBB