Socket
Book a DemoInstallSign in
Socket

@astro-utils/formidable

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astro-utils/formidable

A wrapper for formidable to use with Astro

latest
Source
npmnpm
Version
2.0.3
Version published
Maintainers
1
Created
Source

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

Keywords

astro

FAQs

Package last updated on 30 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.