firebase / quickstart-ios

Firebase Quickstart Samples for iOS
https://firebase.google.com
Apache License 2.0
2.8k stars 1.47k forks source link

Storage SDK: list all files under a dir? #90

Closed myflashlab closed 8 years ago

myflashlab commented 8 years ago

I wonder if there is a way to list all of the available files under a specific dir (folder)?

ianbarber commented 8 years ago

There isn't unfortunately - the path is really just a structured unique identified. However, you can create a reference in the Firebase Realtime Database to the URL, and use that to query if you wanted to keep track - that will also allow arbitrary structuring of queries, but what many people do is mirror the path (so /foo/bar/file in Storage is referenced by /foo/bar/file in the database)

twofishsman commented 8 years ago

i try to find the way out, but still can't list all files under a dir

joelteply commented 7 years ago

Yeah, it seems like an obvious addition. Amazon S3 has a similar setup with its buckets but also offers the ability to list a directory contents. Regardless of the potential ordering of contents, it would be better than nothing to just commit data into the ether and possibly forget about its contents. Using a database is not something we want to do. We ended up zipping up contents, which I hate having to do.

glennposadas commented 6 years ago

Hi everyone, I'd like to follow up on this. I've been searching and reading about similar question. I failed to save the metadata of each photo from Storage to the Database. And furthermore, unfortunately again, each file's name is very unique. The file is named as userId-timestamp. Though each file is saved under a unique folder named after each userId. If only I didn't put a timestamp data in their filenames, I think I'll be able to fetch those all files, but I did. --- Does it mean that I am doomed? There's no way to download all the files? Thanks!

sourabhv commented 6 years ago

Following up on this, there seems to be no way to get all list of files in firebase bucket. But, you can write a script update a firestore collection with all file metadata.

  1. Use gsutil ls gs://{{bucketname}} (or in case of firebase gsutil ls gs://{{project-id}}.appspot.com to get the list of files.

  2. The file url would be https://storage.cloud.google.com/{{project-id}}.appspot.com/{{path}} which is literally https://storage.cloud.google.com/ + whatever the command prints out per line after gs://. This would redirect to another URL. You can save that URL or this one. Being able to access this depends on your security rules.

alxizr commented 6 years ago

@sourabhv can you provide an example with javascript please?

MarcelEdward2 commented 6 years ago

getting a dir list is a basic functionality, how can we get a dir listing. Do we have a bot getting the list out the console or something likw that ?

ducksplash commented 1 year ago

5 years later and it's still not a thing.

To rub salt into the wound, the official documentation shows examples of it - in JavaScript.

Obscene.

peterfriese commented 1 year ago

Did you check out the documentation, @ducksplash ?

https://firebase.google.com/docs/storage/ios/list-files has a code snippet for listing the contents of a storage reference, so it should be straightforward to create a reference to the folder in question and then list its contents, like this:

let storageReference = storage.reference().child("folder/subfolder")
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.
  }
}
ducksplash commented 1 year ago

Did you check out the documentation, @ducksplash ?

https://firebase.google.com/docs/storage/ios/list-files has a code snippet for listing the contents of a storage reference, so it should be straightforward to create a reference to the folder in question and then list its contents, like this:

let storageReference = storage.reference().child("folder/subfolder")
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.
  }
}

I was looking for this in C# for Unity and since this was one of the top results Google gave me for that search query, I assumed that it pertained to C# in Unity, but reading over it again I can see that it does not.

So.. Yes, I did check the documentation, and no, it's still not a thing in C# in the context of unity.