Vid / send_to_backend.py
IgorGent's picture
Upload send_to_backend.py
329efc1 verified
Raw
History Blame Contribute Delete
1.98 kB
import requests
import os
class SendVideoToBackend:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"filenames": ("VHS_FILENAMES",),
"url": ("STRING", {"default": "http://your-backend.com/api/upload"}),
"field_name": ("STRING", {"default": "video"}),
},
"optional": {
"auth_token": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "send_video"
OUTPUT_NODE = True
CATEGORY = "Backend"
def send_video(self, filenames, url, field_name, auth_token=""):
# Ищем именно mp4 файл в списке путей
file_path = None
for path in filenames[1]:
if path.lower().endswith(".mp4"):
file_path = path
break
# Если mp4 не нашли, берем первый доступный файл
if file_path is None:
file_path = filenames[1][0]
if not os.path.exists(file_path):
return (f"Error: File {file_path} not found",)
headers = {}
if auth_token:
headers["Authorization"] = f"Bearer {auth_token}"
# Определяем правильный MIME-тип в зависимости от расширения
mime_type = 'video/mp4' if file_path.lower().endswith(".mp4") else 'image/png'
with open(file_path, 'rb') as f:
files = {field_name: (os.path.basename(file_path), f, mime_type)}
response = requests.post(url, files=files, headers=headers)
if response.status_code == 200:
return (f"Success: {response.text}",)
else:
return (f"Error {response.status_code}: {response.text}",)
NODE_CLASS_MAPPINGS = {"SendVideoToBackend": SendVideoToBackend}
NODE_DISPLAY_NAME_MAPPINGS = {"SendVideoToBackend": "🚀 Send Video to Backend"}