swagger-express-validator icon indicating copy to clipboard operation
swagger-express-validator copied to clipboard

Breaks piping binary data to browser

Open hallvors opened this issue 3 years ago • 0 comments

I tried to add swagger-express-validator to a code base and found that an API returning PDFs fetched from Google cloud storage started returning 0 bytes. This was a surprise and it took me a while to realise adding swagger-express-validator was the cause. The code is quite simple, lots of examples recommend this pattern:

    const gcsBucket = gcs.bucket(bucketName);

    result = await gcsBucket
      .file(gcsFilePath)
      .createReadStream()
      .on("error", function (err) {
        console.log("Error downloadFileFromGcs");
        console.log(err);
        throw new ApiError(404, 'Not found');
      })
      .on("end", function () {
        // The file is fully downloaded.
        console.log("downloadFileFromGcs: The file is fully downloaded.");
      })
      .pipe(res);

hallvors avatar Aug 31 '22 06:08 hallvors