Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Firebase Storage "ListAll" function result says there are no items

Writer Mia Lopez

I am using Firebase Storage to store reviews of songs.

I try to get these reviews by using

 let reviews = Storage.storage().reference().child("users").child(self.thedelegate.currentid).child("reviews") reviews.listAll { (result, error) in
...

but the result says there are no items in the result. I checked for errors - no errors.

It says the count of the result.items array is 0 when I print to the console.

However, in my Firebase Console, the file directory exists, and there are 3 reviews stored in the 'reviews' folder.

I have also made sure that

self.thedelegate.currentid

is printing out the correct user id.

Here is the function code:

 func loadreviews() { print("LOADING REVIEWS") print("CURRENT ID --- \(self.thedelegate.currentid)") let reviews = Storage.storage().reference().child("users").child(self.thedelegate.currentid).child("reviews") reviews.listAll { (result, error) in if error != nil { return } if result.items.count == 0 { print("THERE ARE NO REVIEWS") } else { print("THERE ARE REVIEWS") } for item in result.items { print("CREATING NEW BCELL") let newcell = BCell() newcell.backgroundColor = .clear newcell.selectionStyle = .none newcell.intiailize() Storage.storage().reference().child("users").child(self.thedelegate.currentid).child("reviews").child(item.name).child("songname").getData(maxSize: 4 * 1024) { (data, error) in if error != nil { return } let songname = String(data: data!, encoding: .utf8) newcell.songlabel.text = songname! } Storage.storage().reference().child("users").child(self.thedelegate.currentid).child("reviews").child(item.name).child("artistname").getData(maxSize: 4 * 1024) { (data, error) in if error != nil { return } let artistname = String(data: data!, encoding: .utf8) newcell.artistlabel.text = artistname! } Storage.storage().reference().child("users").child(self.thedelegate.currentid).child("reviews").child(item.name).child("review").getData(maxSize: 4 * 1024) { (data, error) in if error != nil { return } let review = String(data: data!, encoding: .utf8) newcell.reviewlabel.text = review! } Storage.storage().reference().child("users").child(self.thedelegate.currentid).child("reviews").child(item.name).child("time").getData(maxSize: 4 * 1024 * 1024) { (data, error) in if error != nil { return } let stringint = String(data: data!, encoding: .utf8) let interval = Int.init(stringint ?? "") newcell.associatedtime = interval! print("THE REVIEW TIME WAS : ") print(interval!) } newcell.imageview.image = self.thedelegate.correctimage self.reviewcells.append(newcell) self.table.reloadData() } } } 

And the pictures of the console and Firebase Storage website

Firebase Storage sheet

console showing the correct user id

console showing the correct user id

1

1 Answer

Your screenshot shows only folders under reviews, and no actual files. listAll() separates files from folders in its API. Be sure to read the documentation carefully on the matter, and study the sample code it provides:

let storageReference = storage.reference().child("files/uid")
storageReference.listAll { (result, error) in if let error = error { // ... } for prefix in result.prefixes { // The prefixes under storageReference. // You may call listAll(completion:) recursively on them. } for item in result.items { // The items under storageReference. }
}

If you want to list the folders under a location, you should iterate result.prefixes. To find files immediately under a location, you should iterate result.items. If you want to list nested files, you will have to call listAll() again on the nested path.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy