1
Полезные советы, инструкции / Re: Быстрая передача файлов через интернет.
« Последний ответ от totiks2012 Вчера в 10:59:26 »Надо будет глянуть, что за tamtam и какой там api. Может, чего скумекаем
Код
#!/bin/bash
set -x
# Access token
ACCESS_TOKEN="подставить токен бота"
# Get file path from clipboard
FILE_PATH=$(xsel --clipboard --output)
# Check if FILE_PATH is not empty
if [ -z "$FILE_PATH" ]; then
echo "File path not found in clipboard."
exit 1
fi
echo "File path: $FILE_PATH"
# Request upload URL
UPLOAD_URL=$(curl -s -X POST "https://botapi.tamtam.chat/uploads?access_token=${ACCESS_TOKEN}&type=file" \
-H "Content-Type: application/json" | jq -r '.url')
# Check if URL was obtained successfully
if [ -z "$UPLOAD_URL" ]; then
echo "Failed to get upload URL."
exit 1
fi
echo "Upload URL: $UPLOAD_URL"
# Upload the file
response=$(curl -s -i -X POST -H "Content-Type: multipart/form-data" -F "data=@${FILE_PATH}" "$UPLOAD_URL")
# Check if upload was successful
if echo "$response" | grep -q "HTTP/2 200"; then
echo "File uploaded successfully."
# Extract fileId and token from response
FILE_ID=$(echo "$response" | grep -oP '"fileId":\K\d+')
TOKEN=$(echo "$response" | grep -oP '"token":"\K[^"]+')
echo "File ID: $FILE_ID"
echo "Token: $TOKEN"
else
echo "Failed to upload file."
echo "Response:"
echo "$response"
exit 1
fi
![Грустный :(](https://forum.puppyrus.org/Smileys/LightB/sad.gif)