2.0.3 • Published 1 year ago

@astro-utils/formidable v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Astro Formidable

Allow you to use formidable for request parse.

If parsing form data does not work with the default Astro.request.formData().

Usage

pages/upload.json.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.getFile('file');
    if(isFormidableFile(file)){
        const content = await fs.readFile(file.filepath);
        name = file.originalFilename + ' - ' + content.length;
    }

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

1 year ago

2.0.2

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1

2 years ago