Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ if [[ "$#" == '0' ]]; then
echo -e 'ERROR: No File Specified!' && exit 1
fi

# Store the file path, preserving spaces
# $1 is the first command-line argument
FILE="$1"

# Query GoFile API to find the best server for upload
# Use jq to parse JSON response and extract the server name
SERVER=$(curl -s https://api.gofile.io/servers | jq -r '.data.servers[0].name')
# Upload file with progress bar
# Use --progress-bar for a clean progress display
RESPONSE=$(curl --progress-bar -X POST -F "file=@$FILE" "https://upload.gofile.io/uploadfile")

# Upload the file to GoFile
# -# shows a progress bar
# -F specifies form data, "file=@$FILE" uploads the file content
# Use jq to parse JSON response and extract the download page URL
LINK=$(curl -# -F "file=@$FILE" "https://${SERVER}.gofile.io/uploadFile" | jq -r '.data|.downloadPage') 2>&1
# Extract download link
LINK=$(echo "$RESPONSE" | jq -r '.data.downloadPage')

# Display the download link
# Quoting $LINK preserves any spaces or special characters in the URL
echo "$LINK"
# Check if upload succeeded
if [[ "$LINK" == "null" || -z "$LINK" ]]; then
echo -e "\n Upload failed! Full response:"
echo "$RESPONSE"
exit 1
fi

# Print a blank line for better readability
# Print result
echo "$LINK"
echo