0

How can I easily obtain the DataURI of a file in a terminal-based environment? The tool should be installable via apt-get and feature simple syntax. Could you suggest some suitable options? Thank you for your assistance.

2 Answers 2

1

Since data URIs are just a combo of mime type + base64 encoded contents, you can easily create your own script to create a full string. Example from here:

#!/bin/sh
mimetype=$(file -bN --mime-type "$1")
content=$(base64 -w0 < "$1")
echo "url('data:$mimetype;base64,$content')"
0

I figured out that there was a built in tool for that. Typing base64 file.txt > txtbase64.txt will save the DataURI for file.txt inside txtbase64.txt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.