Last active
July 14, 2023 08:05
-
-
Save popeating/72f797ab91e4345057f0882eeabe290c 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 { getSignedUrl } from '@aws-sdk/s3-request-presigner'; | |
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'; | |
export default async function handler(req, res) { | |
const client = new S3Client({ | |
region: process.env.S3_REGION, | |
credentials: { | |
accessKeyId: process.env.S3_ACCESS_KEY, | |
secretAccessKey: process.env.S3_SECRET_KEY, | |
}, | |
}); | |
const command = new PutObjectCommand({ | |
Bucket: process.env.S3_BUCKET_NAME, | |
Key: req.query.file, | |
fileType: req.query.fileType, | |
}); | |
const url = await getSignedUrl(client, command, { expiresIn: 60 }); | |
res.status(200).json({ | |
url: url, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment