Is this Stream Storage Engine implementation correct?
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
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](https://github.com/expressjs/multer/blob/master/StorageEngine.md), 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?
```ts
class StreamEngine implements StorageEngine {
_handleFile(
req: Request,
file: Express.Multer.File,
callback: (error: Error | null, info?: Partial) => 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](https://www.npmjs.com/package/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.
Contributor guide
Assessment
This issue has not been assessed yet.