Last active
May 28, 2023 17:11
-
-
Save rlataguerra/c1a54194d1ab77f8c677fadf49b3471f to your computer and use it in GitHub Desktop.
An example to create a presigned url with Node.js
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
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