Upload Size Limit #721
Answered
by
stafyniaksacha
raven-dever
asked this question in
Q&A
-
Is there a way to configure an upload size limit? For example the body-parser middleware has an option to control the limit of the body size of incoming requests: https://expressjs.com/en/resources/middleware/body-parser.html#limit Does unjs/nitro have some similar config option, utility or middleware? |
Beta Was this translation helpful? Give feedback.
Answered by
stafyniaksacha
Dec 2, 2022
Replies: 1 comment 7 replies
-
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()
})
}) |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
raven-dever
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use formidable in a event handler like: