I am trying to check if an Object exists before generating a SignedUrl. However the SignedUrl returns before the headObject, generating a link that points to non-existing object.
var params = {
Bucket: bucket,
Key: path,
};
var signedURL = "none";
s3.headObject(params, function (err, metadata) {
if (err && err.code === 'NotFound')
params.Key = 'no_image.png';
params.Expires = 900;
s3.getSignedUrl('getObject', params, function (err, url) {
signedURL = url;
if (err)
console.log("Generation of Signed url failed");
else
console.log("Generated Signed url");
});
});
console.log("Generating PreSigned Link ... Success");
return resolve(signedURL);
Looks like following code also does not work:
var someVar = s3.headObject(params);
someVar.then(() ...
How to use promises with AWS headObject?
via Sumit Kumar Ghosh
No comments:
Post a Comment