Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Created August 25, 2020 13:50
Show Gist options
  • Save wmakeev/a295a68fed1bcdbb70131310c9febdd6 to your computer and use it in GitHub Desktop.
Save wmakeev/a295a68fed1bcdbb70131310c9febdd6 to your computer and use it in GitHub Desktop.
[AWS S3 public link] #aws #s3
import AWS from 'aws-sdk'
import { v4 } from 'uuid'
const s3 = new AWS.S3({ signatureVersion: 'v4' })
const { AWS_S3_SCREENSHOT_BUCKET } = process.env
export default async function getImageTempUrl(
prefix: string,
imgBuffer: Buffer
) {
const key = `${prefix}-${Date.now()}-${v4()}`
await s3
.upload({
Bucket: AWS_S3_SCREENSHOT_BUCKET!,
Key: key,
ContentType: 'image/png',
Body: imgBuffer
})
.promise()
const url = s3.getSignedUrl('getObject', {
Bucket: AWS_S3_SCREENSHOT_BUCKET!,
Key: key,
Expires: 60 * 60 * 24 * 6
})
return url
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment