In AWS S3 Bucket, I can see the folders but when I click on a folder, I can see the files but with full path.
example: current folder: myDocuments --- Files: myDocuments/file1.jpg --- myDocuments/file2.jpg and so on...
I want to show: ---- file1.jpg, ----- file2.jpg
here is the code:
service.ts:
getFolderContent(): Observable<any> {
return new Observable((observer) => {
this.loader.next(false);
bucket.listObjectsV2({ Bucket: this.bucketName, Prefix: this.currentFolder, Delimiter: '/' }, (err: AWS.AWSError, data: S3.ListObjectsV2Output) => {
this.loader.next(false);
console.log(data)
if (err) {
observer.error(err);
}
else {
let list: any[] = [];
list = list.concat(data.CommonPrefixes?.map(m => { return { name: m.Prefix, contentType: 'folder' } }));
list = list.concat(data.Contents?.filter(m => m.Key != this.currentFolder).map(m => { return { name: m.Key, contentType: 'file', modifiedTime: m.LastModified?.toDateString() } }));
observer.next(list);
}
});
})
}
getUrl(key:string): Observable<any> {
return new Observable((observer) => {
this.loader.next(true);
bucket.getSignedUrl('getObject',{ Bucket: this.bucketName, Key:key,Expires:60*5 }, (err: Error, url: string) => {
this.loader.next(false);
if (err) {
observer.error(err);
}
else {
observer.next(url);
}
});
})
}
and in file-list.ts
ngOnInit(): void {
this.openFolder(this.s3Service.currentFolder);
}
openFolder(folder: string) {
this.s3Service.currentFolder = folder;
this.s3Service.getFolderContent().subscribe(m => {
this.contentList = m;
})
}
Please try to help me and forward me to others links as I have read alot and found them useless.