-
-
Save LarsBuur/7e9faa8597991f7328df131ac332eb4a to your computer and use it in GitHub Desktop.
[AWS S3 public link] #aws #s3
This file contains hidden or 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 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