h3-formidable
Advanced tools
Comparing version 0.2.1 to 0.2.2
import * as h3 from 'h3'; | ||
import { H3Event } from 'h3'; | ||
import formidable, { Files } from 'formidable'; | ||
export { Files } from 'formidable'; | ||
import formidable, { Fields, Files } from 'formidable'; | ||
export { Fields, Files } from 'formidable'; | ||
declare function readFiles(event: H3Event, options?: formidable.Options): Promise<Files>; | ||
declare function createFileParserMiddleware(options?: formidable.Options): h3.EventHandler<void>; | ||
interface FieldsAndFiles { | ||
fields: Fields; | ||
files: Files; | ||
} | ||
declare function readFiles<T extends boolean | undefined = undefined>(event: H3Event, options?: formidable.Options & { | ||
includeFields?: T; | ||
}): Promise<T extends undefined ? Files : T extends true ? FieldsAndFiles : Fields>; | ||
declare function createFileParserMiddleware<T extends boolean>(options?: formidable.Options & { | ||
includeFields?: T; | ||
}): h3.EventHandler<void>; | ||
export { createFileParserMiddleware, readFiles }; | ||
export { FieldsAndFiles, createFileParserMiddleware, readFiles }; |
@@ -34,5 +34,12 @@ var __create = Object.create; | ||
const form = (0, import_formidable.default)(options); | ||
form.parse(event.node.req, (err, _fields, files) => { | ||
form.parse(event.node.req, (err, fields, files) => { | ||
if (err) | ||
reject(err); | ||
if (options == null ? void 0 : options.includeFields) { | ||
resolve({ | ||
fields, | ||
files | ||
}); | ||
return; | ||
} | ||
resolve(files); | ||
@@ -39,0 +46,0 @@ }); |
{ | ||
"name": "h3-formidable", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "File upload parsing utility for h3 and Nuxt.", | ||
@@ -5,0 +5,0 @@ "author": "Robert Soriano <sorianorobertc@gmail.com>", |
@@ -21,4 +21,9 @@ # h3-formidable | ||
export default eventHandler(async (event) => { | ||
const files = await readFiles(event, { | ||
// https://github.com/node-formidable/formidable#options | ||
// only files | ||
const files = await readFiles(event) | ||
// with fields | ||
const { fields, files } = await readFiles(event, { | ||
includeFields: true, | ||
// other formidable options here | ||
}) | ||
@@ -25,0 +30,0 @@ }) |
Sorry, the diff of this file is not supported yet
7295
102
59