I'm working on a labeling tool for ML, and I want to be able to display the contents of a random folder on a React app so I can label them.I was thinking of finding the amount of folders, searching through the last available folder, and then delete from database. Repeat on refresh. Is this possible? I haven't been able to find out how to return the amount of folders in a directory.
var folders = [];
// Create a reference under which you want to list
var listRef = storageRef.child('path/to/files');
// Find all the prefixes and items.
listRef.listAll().then(function(res) {
res.prefixes.forEach(function(folderRef) {
// All the prefixes under listRef.
folders.push(folderRef);
});
}).catch(function(error) {
// Uh-oh, an error occurred!
});
var selected = []
// Select N=5 at random
for (i=0; i < 5 && folders.length > 0 ; i++){
var index = Math.floor(Math.random() * folders.length)
selected.push(folders[index])
folders.splice(index, 1);
}
You can list the files/folders inside a bucket path. Link . And select one at random of that list.
And similarly with delete files .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.