diff --git a/packages/server/src/utils/requestUtils.ts b/packages/server/src/utils/requestUtils.ts index 28132e3c4..bd15633d8 100644 --- a/packages/server/src/utils/requestUtils.ts +++ b/packages/server/src/utils/requestUtils.ts @@ -64,15 +64,19 @@ export async function formParse(request: IncomingMessage): Promise { - const form = formidable({ multiples: true }); + const form = formidable({ + allowEmptyFiles: true, + minFileSize: 0, + }); form.parse(req, (error: any, fields: Fields, files: Files) => { if (error) { + error.message = `Could not parse form: ${error.message}`; reject(error); return; } @@ -96,6 +100,11 @@ export async function bodyFields(req: any/* , filter:string[] = null*/): Prom return form.fields as T; } +export const bodyFiles = async (req: any/* , filter:string[] = null*/): Promise => { + const form = await formParse(req); + return form.files as T; +}; + export function ownerRequired(ctx: AppContext) { if (!ctx.joplin.owner) throw new ErrorForbidden(); }