Skip to content

Upload Size Limit #721

Answered by stafyniaksacha
raven-dever asked this question in Q&A
Dec 2, 2022 · 1 comments · 7 replies
Discussion options

You must be logged in to vote

You can use formidable in a event handler like:

import formidable from 'formidable'

export default defineEventHandler(async (event) => {
  return new Promise((resolve, reject) => {
    // parse a file upload
    const form = formidable({
      maxFileSize: 2 * 1024 * 1024, // 2MB
    })

    form.parse(event.node.req, async (err, fields, files) => {
      if (err) {
        return reject(
          createError({
            statusCode: 400,
            statusMessage: 'Bad Request',
            message: String(err),
          })
        )
      }

      // handle files

     return resolve()
   })
})

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@ChrisGV04
Comment options

@CKylinMC
Comment options

@ChrisGV04
Comment options

@ChrisGV04
Comment options

@CKylinMC
Comment options

Answer selected by raven-dever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants