Created
July 5, 2026 16:47
-
-
Save bluerid/8143692406d256153c77bac05a20d9d5 to your computer and use it in GitHub Desktop.
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 { S3Client, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3'; | |
| import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; | |
| const s3Clinet = new S3Client({ | |
| region: 'ap-south-1', | |
| credentials: { | |
| accessKeyId: "AKIXXU5XXXXXX", | |
| secretAccessKey: "8SXXeXXK8vynzXXXXXXXX" | |
| } | |
| }); | |
| async function getObjectURL(key) { | |
| const command = new GetObjectCommand({ | |
| Bucket : 'ftrends-26-123456789012-ap-south-1-an', | |
| Key: key | |
| }); | |
| const url = await getSignedUrl(s3Clinet, command); | |
| return url; | |
| } | |
| async function putObject(filename, contentType) { | |
| const command = new PutObjectCommand({ | |
| Bucket: 'ftrends-26-123456789012-ap-south-1-an', | |
| Key: `uploads/${filename}`, | |
| ContentType: contentType | |
| }); | |
| const url = await getSignedUrl(s3Clinet, command, { expiresIn: 60 }); | |
| return url; | |
| } | |
| // console.log("URL for image_b6d71e99.png", await getObjectURL("image_b6d71e99.png")); | |
| console.log("URL for uploading", await putObject(`video-${Date.now()}.jpeg`, "video/mp4")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment