-
-
Save richardgrantserverless/a6e597a514af9db4ce0d8b068e62516d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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