webapp/src/utils/handleFileUpload.ts
2024-05-21 04:03:29 +03:00

20 lines
542 B
TypeScript

import { UploadFile } from '@solid-primitives/upload'
import { UploadedFile } from '../pages/types'
import { coreApiUrl } from './config'
const apiUrl = `${coreApiUrl}/upload`
export const handleFileUpload = async (uploadFile: UploadFile, token: string): Promise<UploadedFile> => {
const formData = new FormData()
formData.append('file', uploadFile.file, uploadFile.name)
const response = await fetch(apiUrl, {
method: 'POST',
body: formData,
headers: {
Authorization: token,
},
})
return response.json()
}