-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UploadFile()
should accept Readable
instead of Buffer
#13158
Comments
The thing is, it can accept While I do think that better memory management is a good thing, there is a balance to be kept between efficient and ergonomic API for developers. |
Perhaps we can make a mention in the docs and the default of buffer and how to use streams if that is the desired approach and why you might want to do that |
If hope to avoid breaking change, I think NestJS guide document must warn the memory problem, and give an example code converting to the streaming strategy. |
Adding a mention in the docs sounds valuable |
I'd tried to make concise On the other hand, Anyway, after I completed this |
@samchon Have you had any chance to contribute to NestJS documentation? :) |
Have forgotten this issue for a long time due to busy. @Shandur Thanks for reminding. It's okay you to contribute eariler. |
@samchon is the issue still in the queue or it has been closed?, if workable, assign it to me! Thanks! |
I'm not maintainer of NestJS, so that as you wish @saram-aman In my case, I've solved this problem just by defining multer instance by closure function parameter like below. https://nestia.io/docs/core/TypedFormData/ import { TypedFormData, TypedRoute } from "@nestia/core";
import { Controller } from "@nestjs/common";
import Multer from "multer";
@Controller("bbs/articles")
export class BbsArticlesController {
@TypedRoute.Post()
public async create(
@TypedFormData.Body(() => Multer({
storage: { ...THE STORAGE ENGINE SETTING }
})) input: IBbsArticleCreate,
): Promise<void> {
input;
}
}
export interface IBbsArticleCreate {
title: string;
body: string | null;
thumbnail?: File | undefined;
files: File[];
tags: string[];
} |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
When using
@UploadFile()
decorator following the NestJS guide documents, it becomesBuffer
type.As you know, the
Buffer
type means that backend server gathers entire data of the uploaded file. If client uploads 1GB file through the API, the NestJS backend server requires at least 1GB memory about the request. If there're 100 clients uploading the 1GB file at the same time, NestJS backend server needs 100GB memory at that time.Describe the solution you'd like
I know that the default option of
multer
is using theBuffer
type instance, but it seems not proper to the full framework like NestJS. If configure storage engine of themulter
, the uploadaed file would beReadable
stream type, and I think NestJS should do it.Teachability, documentation, adoption, migration strategy
I have followed the https://docs.nestjs.com/techniques/file-upload document.
And very surprised by too much memory consumption.
What is the motivation / use case for changing the behavior?
I think NestJS should do like below:
Buffer
feature, they must configure by themselvesThe text was updated successfully, but these errors were encountered: