Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firebase Storage: O que é e como funciona

Firebase Storage: O que é e como funciona

This a presentation that a gave at Android Training Program - Portugal 2020, about what is Firebase Storage and how it works.

Manuel Ernesto

December 03, 2020
Tweet

More Decks by Manuel Ernesto

Other Decks in Programming

Transcript

  1. Firebase Storage: O que é e como funciona Manuel Ernesto

    Software Engineer @ Disruption Lab GDG Lubango Organizer Twitter: @manuelernest0
  2. dependencies { // Import the BoM for the Firebase platform

    implementation platform('com.google.firebase:firebase-bom:26.1.0') // Declare the dependency for the Cloud Storage library // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-storage-ktx' } Configuração
  3. fun uploadFile() { val storageRef = Firebase.storage.reference val file: Uri

    = Uri.fromFile(File("caminho/imagem/atp.png")) val imgRef: StorageReference = storageRef.child("images/") imgRef.putFile(file) .addOnSuccessListener { taskSnapshot -> // Get a URL to the uploaded content } .addOnFailureListener { // Handle unsuccessful uploads } } Upload ⬆
  4. fun uploadFile() { val storageRef = Firebase.storage.reference val file: Uri

    = Uri.fromFile(File("caminho/imagem/atp.png")) val imgRef: StorageReference = storageRef.child("images/") imgRef.putFile(file) .addOnSuccessListener { taskSnapshot -> // Get a URL to the uploaded content } .addOnFailureListener { // Handle unsuccessful uploads } } Upload ⬆
  5. fun downloadFile(){ val storageRef = Firebase.storage.reference val ref = storageRef.child("images/")

    val saveFileInto = File.createTempFile(fileType, fileExt) ref.getFile(saveFileInto).addOnSuccessListener { }.addOnFailureListener{ } } Download ⬇
  6. fun downloadFile(){ val storageRef = Firebase.storage.reference val ref = storageRef.child("images/")

    val saveFileInto = File.createTempFile(fileType, fileExt) ref.getFile(saveFileInto).addOnSuccessListener { }.addOnFailureListener{ } } Download ⬇
  7. fun deleteFile(fileDir: String) { val storageRef = Firebase.storage.reference val ref

    = storageRef.child(fileDir) ref.delete().addOnFailureListener { } .addOnCompleteListener { } } Delete ❌
  8. fun deleteFile(fileDir: String) { val storageRef = Firebase.storage.reference val ref

    = storageRef.child(fileDir) ref.delete().addOnFailureListener { } .addOnCompleteListener { } } Delete ❌