2.0.1 • Published 5 months ago

@astro-utils/formidable v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Astro Formidable

Allow you to use formidable for request parse.

Deprecate because Astro now support multipart/form-data by default

Usage

pages/upload.json.ts

import {parseAstroForm, isFormidableFile} from '@astro-utils/formidable';

export const post: APIRoute = async ({request}) => {
    const formData: FormData = await parseAstroForm(Astro.request);
    let name = 'Not-File'

    const file = formData.get('file');
    if(isFormidableFile(file)){
        name = file.name;
    }

    return {
        body: name
    }
}

pages/index.page

---
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');
    if(isFormidableFile(file)){
        console.log('The user upload a file');
    }
}
---
2.0.1

5 months ago

2.0.0

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.0.1

6 months ago