2
0

🛂 (fileUpload) Improve file upload size limit enforcement

Closes #799, closes #797
This commit is contained in:
Baptiste Arnaud
2023-09-19 15:42:33 +02:00
parent f626c9867c
commit bb13c2bd61
19 changed files with 143 additions and 239 deletions

View File

@ -23,6 +23,7 @@ export const uploadFiles = async ({
i += 1
const { data } = await sendRequest<{
presignedUrl: string
formData: Record<string, string>
hasReachedStorageLimit: boolean
}>(
`${basePath}/storage/upload-url?filePath=${encodeURIComponent(
@ -35,9 +36,14 @@ export const uploadFiles = async ({
const url = data.presignedUrl
if (data.hasReachedStorageLimit) urls.push(null)
else {
const upload = await fetch(url, {
method: 'PUT',
body: file,
const formData = new FormData()
Object.entries(data.formData).forEach(([key, value]) => {
formData.append(key, value)
})
formData.append('file', file)
const upload = await fetch(data.presignedUrl, {
method: 'POST',
body: formData,
})
if (!upload.ok) continue