I have this helper function:
const listFileKeysInSpaceByPrefix = async (prefix) => {
var params = {
Bucket: process.env.S3_BUCKET_NAME,
Prefix: prefix,
};
let fileKeys;
await s3.listObjects(params, function (err, data) {
if (err) {
console.log(err, err.stack);
next(err);
}
let keys = [];
data["Contents"].forEach(function (obj) {
keys.push(obj.Key);
});
console.log("key1", keys);
fileKeys = keys;
});
return fileKeys;
};
And I called the helper function within a route like this:
const keyToBeDeleted = await listFileKeysInSpaceByPrefix(uploadSpaceFolder);
console.log("keys",keyToBeDeleted);
The Result on my console however looks thus:
keys undefined
key1 ['adamter/rr0.png', 'adamter/rt0.png']
I need to get the array in my response when I call the function but I seem not to find a way around this.