firebase-kotlin-sdk
firebase-kotlin-sdk copied to clipboard
Add FirebaseStorage for Android and iOS
Library | Class | Platforms |
---|---|---|
storage | FirebaseStorage | Android, iOS |
I need this module for the app I'm currently building so I'm taking a crack at it. Does anyone have any guidance on how to handle the two platform apis being different? E.g. Android's StorageReference.get/putStream()
vs ios' nothing.
Hi @mjmarathon can you send links to the API docs for the methods you mentioned? Generally, the best way to handle these difference is to find the kotlin way to do the same kind of thing use that instead - for example, the 3 platforms all have different ways to serialise objects so we use kotlin serialization and convert to the platform specific formats under the hood
Hey there @nbransby! Thanks for the quick follow up.
Docs for the aforementioned methods here: https://firebase.google.com/docs/reference/android/com/google/firebase/storage/StorageReference#getStream(com.google.firebase.storage.StreamDownloadTask.StreamProcessor) https://firebase.google.com/docs/reference/android/com/google/firebase/storage/StorageReference#putStream(java.io.InputStream,%20com.google.firebase.storage.StorageMetadata)
If the ios platform sdk doesn't support/use streams I'm unsure about how to keep the streaming methods exposed.
I need this module for the app I'm currently building so I'm taking a crack at it. Does anyone have any guidance on how to handle the two platform apis being different? E.g. Android's
StorageReference.get/putStream()
vs ios' nothing.
I can think of 3 ways to solve that issue:
- You could share putStream and abstract the Stream class, to receive a Stream and call putStream on Android, and receive a NSFile and call putFile on iOS;
- You could share putStream but have a no-op (dummy) implementation on iOS
- You could keep the putStream method only for Android (you might just access it through the StorageReference.android member directly when you want to use it, or you could create a method on StorageReference in androidMain)
I think the 3rd option is the best, at least inside the library. Not everything should be shared. And if you want, you can create an extension function in your final shared code, that calls putFile on iOS and putStream on Android.
Was added in https://github.com/GitLiveApp/firebase-kotlin-sdk/pull/393