This commit is contained in:
ywb
2026-05-29 20:21:46 +08:00
parent 9084c383cc
commit 8035cf29e2
3 changed files with 50 additions and 12 deletions
+9 -10
View File
@@ -781,7 +781,7 @@ class MissionExecutorV3:
def _capture_arm_photo(self, row: int, col: int, side: str,
pose_idx: int, qr_value: str,
upload_index: int = 0) -> Optional[str]:
"""从机械臂摄像头拍照存本地,然后上传到服务器
"""从机械臂摄像头拍照,直接上传到服务器(不保存本地)
upload_index: 从1开始,先正面后背面,由调用方维护
"""
@@ -791,21 +791,17 @@ class MissionExecutorV3:
logger.error("arm snapshot 请求失败")
return None
os.makedirs(PHOTOS_DIR, exist_ok=True)
# 生成文件名(用于上传)
ts = time.strftime("%Y%m%d_%H%M%S")
fname = f"{ts}_r{row}c{col}_{side}_p{pose_idx}_{qr_value[:20]}.jpg"
fpath = os.path.join(PHOTOS_DIR, fname)
with open(fpath, "wb") as f:
f.write(resp.content)
self._log(f" 💾 本地保存: {os.path.basename(fpath)}")
# 上传到服务器
# 直接上传到服务器(不保存本地)
if qr_value:
self._upload_photo(fpath, qr_value, upload_index)
self._upload_photo_bytes(fname, resp.content, qr_value, upload_index)
else:
self._log(" ⚠️ 无二维码,跳过上传")
return fpath
return fname # 返回文件名(用于日志)
except Exception as e:
logger.error(f"拍照异常: {e}")
return None
@@ -820,10 +816,13 @@ class MissionExecutorV3:
"""
try:
filename = os.path.basename(filepath)
headers = {
"Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImZhNTNkZTZiLWE3NjYtNDZmNC05MDUyLTQ2MjUzZTAyNjdmNSIsInVzZXJuYW1lIjoiYWRtaW4ifQ.lC4vKThZo4aAOLsekm2kPgaEJRqRx-YDQWKfHFqxdPNESCKy57l3eIqaKTj2ZjAMaoYAwYlMrv5M1zAOJsO_PA"
}
with open(filepath, "rb") as f:
files = {"file": (filename, f, "image/jpeg")}
data = {"serialNumber": serial_number, "index": str(index)}
resp = requests.post(UPLOAD_URL, files=files, data=data, timeout=30)
resp = requests.post(UPLOAD_URL, files=files, data=data, headers=headers, timeout=30)
if resp.status_code == 200:
self._log(f" ☁️ 上传成功 [{index}]: {filename}")
return True