fix(mobile): 安卓端附件上传改为与 iOS 一致的预签名直传 - #1101
Open
weed33834 wants to merge 1 commit into
Open
Conversation
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
安卓版客户端上传图片/附件始终报错,需要去网页版上传(#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。同时删除了不再使用的
Platform与FileSystem.FileSystemUploadType依赖。Fixes #849