Spaces:
Sleeping
Sleeping
File size: 706 Bytes
decea84 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import { useAuthStore } from '../store/authStore'
export async function uploadCSV(
topic_id: string,
file: File,
): Promise<{ inserted: number }> {
const token = useAuthStore.getState().accessToken
const formData = new FormData()
formData.append('file', file)
formData.append('topic_id', topic_id)
// Cannot use apiFetch here — browser must set Content-Type for multipart boundary
const res = await fetch('/api/upload', {
method: 'POST',
headers: token ? { Authorization: `Bearer ${token}` } : {},
body: formData,
credentials: 'include',
})
if (!res.ok) {
const err = await res.json()
throw new Error(err.detail ?? 'Upload failed')
}
return res.json()
}
|