dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

Encoding issues with fs.pipe & images? #122

Closed btakita closed 5 years ago

btakita commented 5 years ago

I'm using sirv to serve static images. Serve uses the following to write the file to the response stream.

fs.createReadStream(file, opts).pipe(res);

I'm getting a corrupted image with random pixels. Does serverless-http support fs.pipe or is this an issue?

btakita commented 5 years ago

I'm also getting encoding issues using the serve-static library, which also uses fs.pipe.

Attached is the original image & the served image.

favicon

favicon serverless-http

dougmoscrop commented 5 years ago

Are you sure your API gateway is correctly configured to handle binary content encoding and so on?

btakita commented 5 years ago

You're right. The API gateway BinaryMediaTypes & serverless-http global option needs to be configured.

Globals:
  Api:
    BinaryMediaTypes:
      - image~1png
      - image~1gif
      - image~1jpg
      - image~1jpeg
      - image~1x-icon
import serverless from 'serverless-http'
const handler__serverless = serverless(app, {
    binary(headers) {
        return true
    },
})
module.exports.handler = handler__serverless