import { root } from '@repo/core' import { FileController } from '@repo/sdk' import { Platform } from 'react-native' import { Toast } from '@/@share/components' import { handleError } from '@/hooks/data/use-error' export async function uploadFile(params: { uri: string; mimeType?: string; fileName?: string }): Promise { const { uri, mimeType, fileName } = params || {} const file = { 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) const fileController = root.get(FileController) const { data, error } = await handleError(async () => await fileController.uploadS3(formData)) if (error || !data?.data) { Toast.show({ title: '上传失败' }) throw new Error(error?.message || '上传失败') } return data.data }