I made this small code where the code finds the folder i write in the input box and displays it’s content but aws is just sending no directory data to me
Here is the function doing the work
async function getprojectfolders(Prefix, callback){
var params = {
Bucket: process.env.S3_BUCKET || "",
Delimiter: '/',
Prefix: `${Prefix}/`,
};
s3.listObjectsV2(params, function (err, data) {
if (err) {
console.error('There was an error viewing your album:', err.message);
return callback(err, null);
}
console.log(data, "<<< full response data");
if (data.Contents && data.Contents.length > 0) {
const directories = [...new Set(
data.Contents
.map(content => {
const parts = content.Key.split('/');
if (parts.length > 1) {
return parts.slice(0, parts.length - 1).join('/');
}
return null;
})
.filter(Boolean)
)].sort();
console.log(directories, "<<< directories array from contents");
callback(null, directories);
} else {
console.log("No contents found.");
callback(null, []);
}
})
}
and here is the code with initiates this function in a different js file
socket.on("fetchStartUpProjects", async (data) => {
console.log("Fetch Function Recieved",data)
await getprojectfolders(data, (err, directories) => {
if(err){
console.error("There was some error")
}else{
socket.emit('directories', directories);
}
})
// await fetchS3Folder(`code/${data}`, path.join(__dirname, `../tmp/${data}`));
});
socket.on('disconnect', () => {
// console.log('User disconnected');
});
I tried using chatgpt and change the function MULTIPLE TIMES but it still was returning null, Also, I checked manually and there is content that is there in the directory and also the connection with my s3 bucket is good as it is showing me >data, but the >data.commonPrefix is the returning null…