Skip to content

Instantly share code, notes, and snippets.

@gingerbeardman
Forked from devster/file.io.sh
Last active April 25, 2024 05:49
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gingerbeardman/a7737e4c89fccab8605f8538ddaeec0d to your computer and use it in GitHub Desktop.
Save gingerbeardman/a7737e4c89fccab8605f8538ddaeec0d 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/gingerbeardman/a7737e4c89fccab8605f8538ddaeec0d/raw/a78f5253b0fcdbd7b893f91627a29498690356ea/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 [DURATION]\n"
echo "Example: file.io path/to/my/file 1w\n"
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" | php -r 'echo json_decode(fgets(STDIN))->success;')
if [ "1" != "$RETURN" ]; then
echo "An error occured!\nResponse: ${RESPONSE}"
exit 1
fi
KEY=$(echo "$RESPONSE" | php -r 'echo json_decode(fgets(STDIN))->key;')
EXPIRY=$(echo "${RESPONSE}" | php -r 'echo json_decode(fgets(STDIN))->link;')
echo "${URL}/${KEY}" | pbcopy # to clipboard
echo "${URL}/${KEY}" # to terminal
@gingerbeardman
Copy link
Author

gingerbeardman commented May 30, 2018

grep on macOS doesn't support the switch -P (positive look-behind) so I made some changes to this fork.

  • 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

Also see this alternative that uses https://0x0.st which has different expiry and download limits.

@xNicklaj
Copy link

How do I use file.io with wget instead of curl?

@gingerbeardman
Copy link
Author

Sorry @xNicklaj I can't help you with that. Try asking file.io https://www.file.io/#one

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