Skip to content

fix(#1062): 修复 convertImageToBase64 无法解析 convertFileSrc 生成的 URL#1064

Open
LevisBale0824 wants to merge 1 commit intocodexu:devfrom
LevisBale0824:fix/#1062-image-base64-url-parsing
Open

fix(#1062): 修复 convertImageToBase64 无法解析 convertFileSrc 生成的 URL#1064
LevisBale0824 wants to merge 1 commit intocodexu:devfrom
LevisBale0824:fix/#1062-image-base64-url-parsing

Conversation

@LevisBale0824
Copy link
Copy Markdown

## 问题

Issue #1062

附加本地图片发送给视觉模型时,报错 `Failed to convert image to base64: URL is not a valid path`,模型回复无法识别图片内容。

## 原因

`convertImageToBase64()` 使用硬编码前缀匹配(仅处理 `tauri://localhost/``asset://localhost/`)来提取文件路径,但 `convertFileSrc()` 在不同平台/配置下会生成多种 URL 格式(如 `http://asset.localhost/``https://tauri.localhost/` 等),未被覆盖的格式导致路径解析失败。

## 修复

- 使用 `new URL()` 替代硬编码前缀匹配,兼容所有 URL 格式
- 通过 `@tauri-apps/plugin-os``platform()` 处理 Windows 路径前缀(`new URL().pathname` 在 Windows 上返回 `/C:/...`,需去掉前导 `/`## 测试

- Windows 11 上验证:附加本地图片后,视觉模型(GLM-4.1V)成功识别图片内容

@LevisBale0824
Copy link
Copy Markdown
Author

image 本地测试如图

使用 new URL() 替代硬编码前缀匹配,兼容所有平台下
convertFileSrc 生成的不同 URL 格式(http://asset.localhost/、
http://tauri.localhost/、tauri://localhost/、asset://localhost/ 等),
并通过 platform() 处理 Windows 路径前缀。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@LevisBale0824 LevisBale0824 force-pushed the fix/#1062-image-base64-url-parsing branch from 27f4472 to e1d6bda Compare April 19, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant