From e8bdd0e3d89932c555e57768719e43bec06584e6 Mon Sep 17 00:00:00 2001 From: ido Date: Fri, 30 Aug 2024 17:52:10 +0300 Subject: [PATCH] fix(README): docs --- packages/formidable/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/formidable/README.md b/packages/formidable/README.md index e9dc237..8ed74dc 100644 --- a/packages/formidable/README.md +++ b/packages/formidable/README.md @@ -3,21 +3,23 @@ Allow you to use formidable for request parse. -> **Deprecate** because Astro now support `multipart/form-data` by default +> If parsing form data does not work with the default `Astro.request.formData()`. ## Usage `pages/upload.json.ts` ```ts import {parseAstroForm, isFormidableFile} from '@astro-utils/formidable'; +import fs from 'fs/promises'; export const post: APIRoute = async ({request}) => { const formData: FormData = await parseAstroForm(Astro.request); let name = 'Not-File' - const file = formData.get('file'); + const file = formData.getFile('file'); if(isFormidableFile(file)){ - name = file.name; + const content = await fs.readFile(file.filepath); + name = file.originalFilename + ' - ' + content.length; } return { @@ -34,7 +36,7 @@ import {parseAstroForm, isFormidableFile} from '@astro-utils/formidable'; if(Astro.request.method === "POST"){ const formData: FormData = await parseAstroForm(Astro.request); - const file = formData.get('my-file'); + const file = formData.getFile('my-file'); if(isFormidableFile(file)){ console.log('The user upload a file'); }