mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-17 04:51:10 +00:00
fix: missing hostname in devices_names
fix: upload_file for model file
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import List, Dict, Any, Optional
|
||||
import requests
|
||||
from unilabos.utils.log import info
|
||||
from unilabos.config.config import MQConfig, HTTPConfig
|
||||
from unilabos.utils import logger
|
||||
|
||||
|
||||
class HTTPClient:
|
||||
@@ -102,6 +103,30 @@ class HTTPClient:
|
||||
)
|
||||
return response
|
||||
|
||||
def upload_file(self, file_path: str, scene: str = "models") -> requests.Response:
|
||||
"""
|
||||
上传文件到服务器
|
||||
|
||||
使用multipart/form-data格式上传文件,类似curl -F "files=@filepath"
|
||||
|
||||
Args:
|
||||
file_path: 要上传的文件路径
|
||||
scene: 上传场景,可选值为"user"或"models",默认为"models"
|
||||
|
||||
Returns:
|
||||
Response: API响应对象
|
||||
"""
|
||||
with open(file_path, "rb") as file:
|
||||
files = {"files": file}
|
||||
logger.info(f"上传文件: {file_path} 到 {scene}")
|
||||
response = requests.post(
|
||||
f"{self.remote_addr}/api/account/file_upload/{scene}",
|
||||
files=files,
|
||||
headers={"Authorization": f"lab {self.auth}"},
|
||||
timeout=30, # 上传文件可能需要更长的超时时间
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
# 创建默认客户端实例
|
||||
http_client = HTTPClient()
|
||||
|
||||
@@ -97,7 +97,7 @@ class HostNode(BaseROS2DeviceNode):
|
||||
self.bridges = bridges
|
||||
|
||||
# 创建设备、动作客户端和目标存储
|
||||
self.devices_names: Dict[str, str] = {} # 存储设备名称和命名空间的映射
|
||||
self.devices_names: Dict[str, str] = {device_id: self.namespace} # 存储设备名称和命名空间的映射
|
||||
self.devices_instances: Dict[str, ROS2DeviceNode] = {} # 存储设备实例
|
||||
self.device_machine_names: Dict[str, str] = {device_id: "本地", } # 存储设备ID到机器名称的映射
|
||||
self._action_clients: Dict[str, ActionClient] = {} # 用来存储多个ActionClient实例
|
||||
|
||||
Reference in New Issue
Block a user