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