Files
expo-popcore-app/lib/uploadFile.ts
imeepos c5641c1d3c fix: 修复表单相册上传失败bug,优化FormData构造方式
- 移除uploadFile.ts中不必要的Platform判断逻辑
- 保持原始URI不做修改,让React Native底层处理平台差异
- 添加uploadFile单元测试,覆盖主要上传场景
- 简化代码结构,提高可维护性

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-28 13:46:35 +08:00

25 lines
744 B
TypeScript

import { root } from '@repo/core'
import { FileController } from '@repo/sdk'
import { Platform } from 'react-native'
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 formData = new FormData()
formData.append('file', {
uri: uri,
name: fileName || 'uploaded_file.jpg',
type: mimeType || 'image/jpeg',
} as any)
const fileController = root.get(FileController)
const { data, error } = await handleError(async () => await fileController.uploadS3(formData))
if (error || !data?.data) {
throw error || new Error('上传失败')
}
return data.data
}