Guest User

mirroredtogukguk

a guest
Feb 4th, 2026
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Usage:
  4. # ./upload.sh <file_or_url>
  5. # Example (local file):
  6. # ./upload.sh ./myfile.zip
  7. # Example (remote URL):
  8. # ./upload.sh https://example.com/file.zip
  9.  
  10. if [ $# -lt 1 ]; then
  11. echo "Usage: $0 <file_or_url>"
  12. exit 1
  13. fi
  14.  
  15. INPUT="$1"
  16. API_KEY="YOUR_API_KEY" # replace with your actual API key
  17.  
  18. # Step 1: Get upload info
  19. echo "Getting upload info..."
  20. upload_info=$(curl -s -X POST "https://www.mirrored.to/api/v1/get_upload_info" \
  21. -d "api_key=$API_KEY")
  22.  
  23. echo "Raw upload_info: $upload_info"
  24.  
  25. upload_id=$(echo "$upload_info" | jq -r '.message.upload_id // empty')
  26. file_upload_url=$(echo "$upload_info" | jq -r '.message.file_upload_url // empty')
  27. remote_upload_url=$(echo "$upload_info" | jq -r '.message.remote_upload_url // empty')
  28. default_mirrors=$(echo "$upload_info" | jq -r '.message.default_mirrors | map(.[0]) | join(",") // empty')
  29.  
  30. if [ -z "$upload_id" ]; then
  31. echo "Failed to get upload info."
  32. exit 1
  33. fi
  34.  
  35. echo "Upload ID: $upload_id"
  36. echo "Default mirrors: $default_mirrors"
  37.  
  38. # Step 2: Decide local vs remote
  39. if [[ "$INPUT" =~ ^https?:// ]]; then
  40. echo "Detected remote URL upload..."
  41. response=$(curl -s -X POST "$remote_upload_url" \
  42. -d "api_key=$API_KEY" \
  43. -d "upload_id=$upload_id" \
  44. -d "remote_url=$INPUT")
  45. else
  46. echo "Detected local file upload..."
  47. if [ ! -f "$INPUT" ]; then
  48. echo "Error: File '$INPUT' not found!"
  49. exit 1
  50. fi
  51. response=$(curl -s -X POST "$file_upload_url" \
  52. -F "api_key=$API_KEY" \
  53. -F "upload_id=$upload_id" \
  54. -F "Filedata=@$INPUT")
  55. fi
  56.  
  57. echo "Upload response: $response"
  58.  
  59. # Step 3: Finish upload
  60. echo "Finishing upload..."
  61. finish_response=$(curl -s -X POST "https://www.mirrored.to/api/v1/finish_upload" \
  62. -d "api_key=$API_KEY" \
  63. -d "upload_id=$upload_id" \
  64. -d "mirrors=$default_mirrors")
  65.  
  66. echo "Finish response: $finish_response"
  67.  
  68. # Extract final URLs
  69. file_id=$(echo "$finish_response" | jq -r '.file_id // empty')
  70. full_url=$(echo "$finish_response" | jq -r '.full_url // empty')
  71. short_url=$(echo "$finish_response" | jq -r '.short_url // empty')
  72.  
  73. if [ -n "$full_url" ]; then
  74. echo "File uploaded successfully!"
  75. echo "File ID: $file_id"
  76. echo "Full URL: $full_url"
  77. echo "Short URL: $short_url"
  78. else
  79. echo "Upload failed or no URL returned."
  80. fi
  81.  
Tags: mirroredto
Add Comment
Please, Sign In to add comment