-1

I read the docs and noticed I can only set the max expire time to 7 days and the default time if not set is 15 minutes and the pre-signed URL I generated expires and is not more accessible. So I'm looking for a way that once the pre-signed URL is created it should last forever or if possible keep auto regenerating after it expires.

Here's a piece of my code:

exports.getUser = async (req, res) => {
  try {
    const userId = req.params.userId; // Retrieve the user ID from the request parameters
    
    // Retrieve the user information from the database using the user ID
    const user = await User.findById(userId);

    if (!user) {
      return res.status(404).json({ error: 'User not found' });
    }

    // Check if the value of the profileImage field in the database is the default user image
    if (user.profileImage === defaultProfileImageUrl) {
      // The image does not exist in the S3 bucket, so set the profileImage field to the default user image
      user.profileImage = defaultProfileImageUrl;
    } else { // The image exists in the S3 bucket, so get the signed URL for the image
      const getObjectParams = {
        Bucket: process.env.S3_BUCKET_NAME,
        Key: `${userId}-${user.profileImage}-profile-image.jpg`,
      }
      const command = new GetObjectCommand(getObjectParams)
      const url = await getSignedUrl(s3, command)
      user.profileImage = url
    }
    console.log(user)
    res.status(200).json({ user });
  } catch (err) {
    console.log(err)
    res.status(500).json({ error: 'Failed to retrieve user information!' });
  }
};

I didn't set the expires in before because I taught I'll never expire then but now I know what happens, please I need help on this

Rawley
  • 17
  • 6
  • 2
    It is not possible, a for ever pre signed URL kills the reasoning of whole logic behind pre-signed URL – Piyush Patil Aug 23 '23 at 00:34
  • exactly what @PiyushPatil said - point of signed urls is to give a limited time access to the resource. if you want to have a permanent link to the resource, consider creating a new S3 bucket and make it public – GoranLegenda Aug 23 '23 at 09:12

0 Answers0