From 38af932c6e368bcda5dbde3befb83f7148919c5f Mon Sep 17 00:00:00 2001 From: Ali Afraz Date: Thu, 30 Nov 2023 10:22:58 +0330 Subject: [PATCH] fix nodejs s3 docs. --- pages/app-deploy/nodejs/object-storage.js | 34 ++++++++--------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/pages/app-deploy/nodejs/object-storage.js b/pages/app-deploy/nodejs/object-storage.js index 116a1aca..4ff3d708 100644 --- a/pages/app-deploy/nodejs/object-storage.js +++ b/pages/app-deploy/nodejs/object-storage.js @@ -203,36 +203,26 @@ client.send(new GetObjectCommand(params), (error, data) => {

نمونه کد جهت دریافت لینک دانلود فایل:

{`const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3"); +const { getSignedUrl } = require("@aws-sdk/s3-request-presigner"); require("dotenv").config(); +const filename = "example_filename.png"; // change this to your filename + const client = new S3Client({ - region: "default", - endpoint: process.env.LIARA_ENDPOINT, - credentials: { - accessKeyId: process.env.LIARA_ACCESS_KEY, - secretAccessKey: process.env.LIARA_SECRET_KEY - }, + region: "default", + endpoint: process.env.LIARA_ENDPOINT, + credentials: { + accessKeyId: process.env.LIARA_ACCESS_KEY, + secretAccessKey: process.env.LIARA_SECRET_KEY, + }, }); const params = { - Bucket: process.env(LIARA_BUCKET_NAME), - Key: "objectkey", - Expires: 60, // expires in 60 seconds + Bucket: process.env.LIARA_BUCKET_NAME, + Key: filename, }; -// async/await const command = new GetObjectCommand(params); -const url = await client.getSignedUrl(command); - -// callback -const command = new GetObjectCommand(params); - -client.getSignedUrl(command, (error, url) => { - if (error) { - console.log(error); - } else { - console.log(url); - } -});`} +getSignedUrl(client, command).then((url) => console.log(url));`}

دریافت لیست فایل‌های آپلود شده توسط AWS SDK