You are not logged in.

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

clusterF
Member
Registered: 2019-05-07
Posts: 168

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 bit.ly.

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
		mimeType="${mimeType};charset=utf-8";
	fi
	echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"

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


Everything not saved will be lost.

--Nintendo "Quit Screen" message

Offline

Board footer

Powered by FluxBB