Socket
Socket
Sign inDemoInstall

h3-formidable

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3-formidable

File upload parsing utility for h3 and Nuxt.


Version published
Weekly downloads
1.3K
increased by27.79%
Maintainers
1
Weekly downloads
 
Created
Source

h3-formidable

npm (tag) NPM

File upload parsing utility for h3 and Nuxt using formidable.

Demo - https://stackblitz.com/edit/nuxt-starter-ykuwmn

Install

npm install h3-formidable

Usage with Nuxt

  1. Create a server middleware
import { createFileParserMiddleware } from 'h3-formidable'

export default createFileParserMiddleware({})
  1. Access files in your api route
export default eventHandler(async (event) => {
  const { files } = event.context
})

or you can ditch server middleware and parse files per api route...

import { readFiles } from 'h3-formidable'

export default eventHandler(async (event) => {
  // only files
  const files = await readFiles(event)

  // with fields
  const { fields, files } = await readFiles(event, {
    includeFields: true,
    // other formidable options here
  })
})

Usage with H3

import { createFileParserMiddleware } from 'h3-formidable'

const app = createApp()
app
  .use(createFileParserMiddleware({}))
  .use(eventHandler((event) => {
    // event.context.files contains parsed files
  }))

TypeScript Shim

declare module 'h3' {
  import type { Files } from 'h3-formidable'

  interface H3EventContext {
    files: Files
  }
}

License

MIT

Keywords

FAQs

Package last updated on 24 Jun 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc