Skip to content

fix(mobile): 安卓端附件上传改为与 iOS 一致的预签名直传 - #1101

Open
weed33834 wants to merge 1 commit into
chaitin:mainfrom
weed33834:fix/849-android-upload
Open

fix(mobile): 安卓端附件上传改为与 iOS 一致的预签名直传#1101
weed33834 wants to merge 1 commit into
chaitin:mainfrom
weed33834:fix/849-android-upload

Conversation

@weed33834

Copy link
Copy Markdown

问题

安卓版客户端上传图片/附件始终报错,需要去网页版上传(#849)。

根因

移动端走的是「预签名直传」:先 POST /api/v1/uploader/presign 拿到 OSS 预签名 URL,再 PUT 原始字节到该 URL。OSS V1 预签名要求请求头与签名时保持一致——即不能额外携带 Content-Type,否则签名不匹配会返回 403。

iOS 端已改为 fetch(ArrayBuffer) 上传(RN 网络层发送 ArrayBuffer 不会自动补 Content-Type),因此正常。而安卓端仍走 FileSystem.uploadAsync(..., BINARY_CONTENT),这条原生上传路径在安卓上存在平台差异,导致直传失败。

修复

把安卓端与 iOS 端统一为同一条直传路径:

  • FileSystem.readAsStringAsync(uri, { encoding: Base64 }) 读取本地文件再解码为 ArrayBuffer(iOS/Android 通用,避免 RN 网络层在安卓上对 file:// 读取的兼容性问题);
  • 统一用 fetch(uploadUrl, { method: 'PUT', body, credentials: 'omit' }) 上传,两端都不自动补 Content-Type

同时删除了不再使用的 PlatformFileSystem.FileSystemUploadType 依赖。

Fixes #849

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