Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Signed URL without Async await like we have in V2 #6425

Closed
2 tasks
nikhilmisra63 opened this issue Aug 31, 2024 · 3 comments
Closed
2 tasks

Need Signed URL without Async await like we have in V2 #6425

nikhilmisra63 opened this issue Aug 31, 2024 · 3 comments
Assignees
Labels
closed-for-staleness feature-request New feature or enhancement. May require GitHub community feedback. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@nikhilmisra63
Copy link

Describe the feature

Need to generate S3 Signed URL without async await as after updating to v3 it is breaking my code.

Use Case

Need this feature because in mongo db serialization I'm generating signed url before sending response to frontend and there in toJSON method we can not call a method using await.

schema.methods.toJSON = async function () {
  const story = this.toObject();
  story.contentUrl = story.content
    ? await generateSignedUrl(story.content)
    : undefined;
  return story;
};

this is what I was doing in v2 and it is not working after v3 update.

Proposed Solution

support v2 method of generating signed url

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

SDK version used

v3

Environment details (OS name and version, etc.)

Mac, ubuntu

@nikhilmisra63 nikhilmisra63 added feature-request New feature or enhancement. May require GitHub community feedback. needs-triage This issue or PR still needs to be triaged. labels Aug 31, 2024
@aBurmeseDev
Copy link
Member

HI @nikhilmisra63 - thanks for reaching out.

Here's code example of v3 to generate pre-signed URL without using async/await:

const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");

// Create an S3 client
const s3Client = new S3Client({ region: "your-aws-region" });

// Function to generate a pre-signed URL
function generateSignedUrl(key) {
  const command = new GetObjectCommand({
    Bucket: "your-bucket-name",
    Key: key,
  });

  // Generate the pre-signed URL
  return getSignedUrl(s3Client, command, { expiresIn: 3600 });
}

// Usage example
const objectKey = "path/to/your/object.jpg";
const signedUrl = generateSignedUrl(objectKey);
console.log(signedUrl);

Since the getSignedUrl function returns a Promise, you can directly assign the result to a variable without using async/await.

schema.methods.toJSON = function () {
  const story = this.toObject();
  story.contentUrl = story.content
    ? generateSignedUrl(story.content)
    : undefined;
  return story;
};

Hope it helps!
Best,
John

@aBurmeseDev aBurmeseDev self-assigned this Sep 2, 2024
@aBurmeseDev aBurmeseDev added p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2024
Copy link

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 27, 2024
@github-actions github-actions bot closed this as completed Oct 2, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-for-staleness feature-request New feature or enhancement. May require GitHub community feedback. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants