Skip to content

Instantly share code, notes, and snippets.

@richardgrantserverless
Created May 20, 2022 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardgrantserverless/7bfd084c970b361e80a60cd0bb13eeb7 to your computer and use it in GitHub Desktop.
Save richardgrantserverless/7bfd084c970b361e80a60cd0bb13eeb7 to your computer and use it in GitHub Desktop.
async resize(size, path) {
try {
...
const Bucket = process.env.BUCKET
const streamResize = sharp()
.resize(width, height)
.toFormat('png')
const readStream = s3Handler.readStream({ Bucket, Key })
const { writeStream, uploaded } = s3Handler.writeStream({ Bucket, Key: newKey })
readStream
.pipe(streamResize)
.pipe(writeStream)
await uploaded
return newKey
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment