From 78e0ae643c8eb9817b3396cf07a263ce9f03fc4c Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Wed, 29 Apr 2020 22:38:24 +0200 Subject: Fix MultipartReader for big files (#4865) --- std/mime/multipart.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'std/mime/multipart.ts') diff --git a/std/mime/multipart.ts b/std/mime/multipart.ts index b2ac8dcdd..6aadef938 100644 --- a/std/mime/multipart.ts +++ b/std/mime/multipart.ts @@ -308,7 +308,7 @@ export class MultipartReader { } // file let formFile: FormFile | undefined; - const n = await copy(p, buf); + const n = await copyN(p, buf, maxValueBytes); const contentType = p.headers.get("content-type"); assert(contentType != null, "content-type must be set"); if (n > maxMemory) { @@ -319,11 +319,8 @@ export class MultipartReader { postfix: ext, }); try { - const size = await copyN( - new MultiReader(buf, p), - file, - maxValueBytes - ); + const size = await copy(new MultiReader(buf, p), file); + file.close(); formFile = { filename: p.fileName, @@ -333,6 +330,7 @@ export class MultipartReader { }; } catch (e) { await remove(filepath); + throw e; } } else { formFile = { -- cgit v1.2.3