Skip to content

Instantly share code, notes, and snippets.

@devster
Last active February 15, 2024 17:15
Show Gist options
  • Save devster/e6a591879fd9c68b86c9 to your computer and use it in GitHub Desktop.
Save devster/e6a591879fd9c68b86c9 to your computer and use it in GitHub Desktop.
Simple cli tool to use file.io https://www.file.io/#one Install: curl https://gist.githubusercontent.com/devster/e6a591879fd9c68b86c9/raw/87b826fdf20d1669fd99cbf5aa1f105e8a72a3a1/file.io.sh | sudo tee /usr/local/bin/file.io && sudo chmod +x /usr/local/bin/file.io
#!/bin/sh
URL="https://file.io"
DEFAULT_EXPIRE="14d" # Default to 14 days
if [ $# -eq 0 ]; then
echo "Usage: file.io FILE [EXPIRE]"
echo " Example: file.io path/to/my/file 1w"
echo " This example upload your file for 1 download and expires until 7 days if not downloaded."
echo "\nSee documentation at https://www.file.io/#one"
exit 1
fi
FILE=$1
EXPIRE=${2:-$DEFAULT_EXPIRE}
if [ ! -f "$FILE" ]; then
echo "File ${FILE} not found"
exit 1
fi
RESPONSE=$(curl -F "file=@${FILE}" "${URL}/?expires=${EXPIRE}")
RETURN=$(echo "${RESPONSE}" | grep -Po '(?<=success).[^",}]*' | cut -d':' -f2 | tr -d '[[:space:]]')
if [ "true" != "$RETURN" ]; then
echo "An error occured!\nThere is the file.io response: ${RESPONSE}"
exit 1
fi
KEY=$(echo "${RESPONSE}" | grep -Po '(?<=key)[":\s]+.*?"' | cut -d':' -f2 | tr -d '[[:space:]]' | tr -d '"')
EXPIRY=$(echo "${RESPONSE}" | grep -Po '(?<=expiry)[":\s]+.*?"' | cut -d':' -f2 | tr -d '[[:space:]]' | tr -d '"')
echo "Upload done!\nYou can share the download link (expires in ${EXPIRY}): ${URL}/${KEY}"
@gingerbeardman
Copy link

gingerbeardman commented May 30, 2018

Thanks for this!

But grep on macOS doesn't support the switch -P (positive look-behind) so I made some changes to my fork: https://gist.github.com/gingerbeardman/a7737e4c89fccab8605f8538ddaeec0d

  • parse json using php rather than grep+cut+tr
  • show the more minimal progress bar rather than the detailed meter
  • copies link to clipboard on successful upload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment