Skip to content

Is this Stream Storage Engine implementation correct? #1291

@darcyrush

Description

@darcyrush

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions