Skip to content

Instantly share code, notes, and snippets.

@rlataguerra
Last active May 28, 2023 17:11
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 rlataguerra/c1a54194d1ab77f8c677fadf49b3471f to your computer and use it in GitHub Desktop.
Save rlataguerra/c1a54194d1ab77f8c677fadf49b3471f to your computer and use it in GitHub Desktop.
An example to create a presigned url with Node.js
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
const connectedClient = new S3Client({
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
},
endpoint: `https://${process.env.S3_ENDPOINT}`,
region: 'eu-east-1',
});
const command = new PutObjectCommand({
Bucket: 'YOUR_BUCKET_NAME',
Key: 'doppio/presignedtest' + Date.now() + '.pdf', //filename, 'doppio' will become a folder
ContentType: 'application/pdf',
});
const url = getSignedUrl(connectedClient, command, { expiresIn: 3600 });
url.then(url => {
console.log(url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment