dangthr commited on
Commit
0bee1ae
·
verified ·
1 Parent(s): 4ea9e2d

Update remote_uploader.py

Browse files
Files changed (1) hide show
  1. remote_uploader.py +7 -2
remote_uploader.py CHANGED
@@ -7,6 +7,7 @@ import json
7
  import base64
8
  import logging
9
  import sys
 
10
 
11
  # 配置日志
12
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -21,7 +22,9 @@ class WebSocketFileUploader:
21
  async def connect_and_upload(self, upload_dir):
22
  """连接到 WebSocket 服务器并上传文件"""
23
  # 将 HTTP URL 转换为 WebSocket URL
24
- ws_url = self.server_url.replace('http://', 'ws://').replace('https://', 'wss://').rstrip('/')
 
 
25
  ws_url += f'/ws/upload/{self.space_id}?token={self.api_key}'
26
 
27
  logger.info(f"正在连接到 WebSocket: {ws_url}")
@@ -142,7 +145,9 @@ class WebSocketFileUploader:
142
  return False
143
 
144
  # 构建完整的 API 端点 URL
145
- upload_url = f"{self.server_url.rstrip('/')}/api/remote_upload"
 
 
146
 
147
  # 准备请求头
148
  headers = {
 
7
  import base64
8
  import logging
9
  import sys
10
+ import time
11
 
12
  # 配置日志
13
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
22
  async def connect_and_upload(self, upload_dir):
23
  """连接到 WebSocket 服务器并上传文件"""
24
  # 将 HTTP URL 转换为 WebSocket URL
25
+ # 清理URL,移除可能的换行符和空格
26
+ clean_server_url = self.server_url.strip()
27
+ ws_url = clean_server_url.replace('http://', 'ws://').replace('https://', 'wss://').rstrip('/')
28
  ws_url += f'/ws/upload/{self.space_id}?token={self.api_key}'
29
 
30
  logger.info(f"正在连接到 WebSocket: {ws_url}")
 
145
  return False
146
 
147
  # 构建完整的 API 端点 URL
148
+ # 清理URL,移除可能的换行符和空格
149
+ clean_server_url = self.server_url.strip()
150
+ upload_url = f"{clean_server_url.rstrip('/')}/api/remote_upload"
151
 
152
  # 准备请求头
153
  headers = {