Last active
February 15, 2024 17:15
-
-
Save devster/e6a591879fd9c68b86c9 to your computer and use it in GitHub Desktop.
Revisions
-
devster revised this gist
Aug 4, 2015 . No changes.There are no files selected for viewing
-
devster revised this gist
Aug 4, 2015 . No changes.There are no files selected for viewing
-
devster created this gist
Aug 4, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/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}"