Skip to content

Commit

Permalink
fix(README): docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Aug 30, 2024
1 parent 39ecae6 commit e8bdd0e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/formidable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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');
}
Expand Down

0 comments on commit e8bdd0e

Please sign in to comment.