This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@astro-utils/formidable
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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');
    }
}
---

Package Sidebar

Install

npm i @astro-utils/formidable

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

12.1 kB

Total Files

7

Last publish

Collaborators

  • ido.pluto