Skip to content

Instantly share code, notes, and snippets.

@mathieu-aubin
Created November 8, 2021 14:50
Show Gist options
  • Save mathieu-aubin/c378f4fb59d73cc41c26e3c849834080 to your computer and use it in GitHub Desktop.
Save mathieu-aubin/c378f4fb59d73cc41c26e3c849834080 to your computer and use it in GitHub Desktop.
base64 web data
#!/bin/bash
if [ ! -e "${1}" ]; then
echo "File not found";
echo "Usage: $(basename "${0}") input_file";
else
type=$(file --mime-type --brief "${1}");
w="$(echo $type|cut -d/ -f2)";
raw=$(cat "${1}" | base64 -iw0 | sed 's| ||g');
tmpf=$(mktemp);
echo -e "---- ${w^^}64 OUTPUT FOR: ${1} ----\n\ndata:${type};base64,${raw}\n\n---- END ${w^^}64 OUTPUT FOR: ${1} ----" > $tmpf;
cat $tmpf;
echo "data:${type};base64,"$raw | sed 's|\n||g' | sed 's| ||g' > $tmpf;
echo -e "\nURL READY OUTPUT SAVED TO: $tmpf";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment