Skip to content
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

Is this Stream Storage Engine implementation correct? #1291

Open
darcyrush opened this issue Dec 20, 2024 · 0 comments
Open

Is this Stream Storage Engine implementation correct? #1291

darcyrush opened this issue Dec 20, 2024 · 0 comments
Labels

Comments

@darcyrush
Copy link

darcyrush commented Dec 20, 2024

I want access to the ReadStream stream from Multer to pass through my application to then consume somewhere later in my application.

From the README.md link, I followed a very basic implementation to simply expose the ReadStream from file.stream. I removed all error handling and stream cleanup to provide a terse example.

I am having issues (might be NestJS framework related, or it might be my implementation below). Can anyone confirm the success callback works if simply providing the internal file.stream object is enough, as below?

class StreamEngine implements StorageEngine {
  _handleFile(
    req: Request,
    file: Express.Multer.File,
    callback: (error: Error | null, info?: Partial<AsyncFile>) => void,
  ): void {
    // Not sure a passThrough is even needed
    const passThrough = new PassThrough();
    file.stream.pipe(passThrough);

    // Execution reaches this callback, but the execution 
    // doesn't continue later in the NestJS framework controller
    callback(null, { fieldname: file.fieldname, stream: passThrough });
  })
  _removeFile(
    req: Request,
    file: AsyncFile,
    callback: (error: Error | null) => void,
  ): void {
    callback(null);
  }
}

In my case, once Multer reaches the success callback the application doesn't continue (In my NestJS framework controller).

(I'm not even sure a passThrough has any benefit given I am not transforming the stream at all but without it I have the same issue.)

In my application I pass the Readable to another library (form-data) to consume the stream. My implementation after receiving the express file object seems correct since I tested by manually creating a test ReadStream via Readable.from(createReadStream("./50Mbfile") and passing that through to the form-data library and it works as expected.

I am still working on a minimal reproduction example without an additional framework like NestJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant