Problem:
Users will upload a file and fetch it later on.The Bucket and objects will be private. To upload a file, I'm using s3 pre-signed url. Front end will get this url and upload the file to this url. Now issue is related to fetching the file. To fetch the file, I'm creating a presigned url and storing it in database during upload procees.
const params = {
Bucket: process.env.DEFAULT_TENANT_BUCKET,
Key: filePath,
Expires: expiryTime
};
const s3 = new AWS.S3();
let uploadURL = s3.getSignedUrl('putObject', params);
return uploadURL;
const s3 = new AWS.S3();
let uploadURL = s3.getSignedUrl('getObject', params);
return getURL; // This will be stored in database
But signed url will expire after some time even if we dont specific any expiry time. so I cannot store this presigned url in database.
Another Approah:
Instead of storing the getUrl in database, store the filePath, and create the signed url fetch when front end will fetch this data.
Issue with above approach:
- If user list is download in excel format and it contains the url to the file, that url will also be invalid after some period of time.
- When users list is large, create signed url can takes time.
Is there any better approach to this problem?