IgorGent commited on
Commit
329efc1
·
verified ·
1 Parent(s): 666b916

Upload send_to_backend.py

Browse files
Files changed (1) hide show
  1. send_to_backend.py +55 -0
send_to_backend.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+
4
+ class SendVideoToBackend:
5
+ @classmethod
6
+ def INPUT_TYPES(s):
7
+ return {
8
+ "required": {
9
+ "filenames": ("VHS_FILENAMES",),
10
+ "url": ("STRING", {"default": "http://your-backend.com/api/upload"}),
11
+ "field_name": ("STRING", {"default": "video"}),
12
+ },
13
+ "optional": {
14
+ "auth_token": ("STRING", {"default": ""}),
15
+ }
16
+ }
17
+
18
+ RETURN_TYPES = ("STRING",)
19
+ FUNCTION = "send_video"
20
+ OUTPUT_NODE = True
21
+ CATEGORY = "Backend"
22
+
23
+ def send_video(self, filenames, url, field_name, auth_token=""):
24
+ # Ищем именно mp4 файл в списке путей
25
+ file_path = None
26
+ for path in filenames[1]:
27
+ if path.lower().endswith(".mp4"):
28
+ file_path = path
29
+ break
30
+
31
+ # Если mp4 не нашли, берем первый доступный файл
32
+ if file_path is None:
33
+ file_path = filenames[1][0]
34
+
35
+ if not os.path.exists(file_path):
36
+ return (f"Error: File {file_path} not found",)
37
+
38
+ headers = {}
39
+ if auth_token:
40
+ headers["Authorization"] = f"Bearer {auth_token}"
41
+
42
+ # Определяем правильный MIME-тип в зависимости от расширения
43
+ mime_type = 'video/mp4' if file_path.lower().endswith(".mp4") else 'image/png'
44
+
45
+ with open(file_path, 'rb') as f:
46
+ files = {field_name: (os.path.basename(file_path), f, mime_type)}
47
+ response = requests.post(url, files=files, headers=headers)
48
+
49
+ if response.status_code == 200:
50
+ return (f"Success: {response.text}",)
51
+ else:
52
+ return (f"Error {response.status_code}: {response.text}",)
53
+
54
+ NODE_CLASS_MAPPINGS = {"SendVideoToBackend": SendVideoToBackend}
55
+ NODE_DISPLAY_NAME_MAPPINGS = {"SendVideoToBackend": "🚀 Send Video to Backend"}