Skip to content

Instantly share code, notes, and snippets.

@richardgrantserverless
Created May 20, 2022 01:03
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/a6e597a514af9db4ce0d8b068e62516d to your computer and use it in GitHub Desktop.
Save richardgrantserverless/a6e597a514af9db4ce0d8b068e62516d to your computer and use it in GitHub Desktop.
import * as AWS from "aws-sdk";
import stream from "stream";
const S3 = new AWS.S3();
class S3Handler {
constructor() {}
readStream({ Bucket, Key }) {
return S3.getObject({ Bucket, Key }).createReadStream();
}
writeStream({ Bucket, Key }) {
const passThrough = new stream.PassThrough();
return {
writeStream: passThrough,
uploaded: S3.upload({
ContentType: "image/png",
Body: passThrough,
Bucket,
Key
}).promise()
};
}
}
export const s3Handler = new S3Handler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment