fix: 修复表单相册上传失败bug,优化FormData构造方式

- 移除uploadFile.ts中不必要的Platform判断逻辑
- 保持原始URI不做修改,让React Native底层处理平台差异
- 添加uploadFile单元测试,覆盖主要上传场景
- 简化代码结构,提高可维护性

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
imeepos
2026-01-28 13:46:35 +08:00
parent cd1a4f6841
commit c5641c1d3c
4 changed files with 115 additions and 14 deletions

View File

@@ -6,13 +6,12 @@ import { handleError } from '@/hooks/use-error'
export async function uploadFile(params: { uri: string; mimeType?: string; fileName?: string }): Promise<string> {
const { uri, mimeType, fileName } = params
const file = {
const formData = new FormData()
formData.append('file', {
uri: uri,
name: fileName || 'uploaded_file.jpg',
type: mimeType || 'image/jpeg',
uri: Platform.OS === 'android' ? uri : uri.replace('file://', ''),
}
const formData = new FormData()
formData.append('file', file as any)
} as any)
const fileController = root.get(FileController)
const { data, error } = await handleError(async () => await fileController.uploadS3(formData))