Skip to content

Instantly share code, notes, and snippets.

@popeating
Last active July 14, 2023 08:05
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 popeating/72f797ab91e4345057f0882eeabe290c to your computer and use it in GitHub Desktop.
Save popeating/72f797ab91e4345057f0882eeabe290c to your computer and use it in GitHub Desktop.
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