Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check progress of image upload to Firebase storage [closed]

When the user registers for my app they choose a profile picture, input a name, email, and password. I use firebase to authenticate them using email and password. I am using FIRAuth.auth()?.addAuthStateDidChangeListener to detect the change in a user's authentication status. If the user has been authenticated the code inside executes (this code sends the user to the next viewController). The problem is that the code inside fires off before my data can be added to the realtime database and FirebaseStorage. Is there a way to monitor when both tasks have succeeded so then I can trigger the change of view controllers? Thank you.

like image 681
Taylor Simpson Avatar asked Aug 22 '16 22:08

Taylor Simpson


People also ask

Is Firebase good for storing images?

The Firebase SDKs for Cloud Storage add Google security to file uploads and downloads for your Firebase apps, regardless of network quality. You can use our SDKs to store images, audio, video, or other user-generated content. On the server, you can use Google Cloud Storage APIs to access the same files.

Is Firebase Storage realtime?

Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing: Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model.


1 Answers

Firebase has a tutorial on how to track the progress of file uploaded to their servers:

let storageRef = FIRStorage.reference().child("folderName/file.jpg");
let localFile: NSURL = // get a file;

// Upload the file to the path "folderName/file.jpg"
let uploadTask = storageRef.putFile(localFile, metadata: nil)

let observer = uploadTask.observeStatus(.Progress) { snapshot in
  print(snapshot.progress) // NSProgress object
}

This snapshot gives you useful information, such as the total size of the file in bytes and how many bytes have been uploaded so far. Using this information, you can calculate the percentage uploaded and use it to update any UI control in your app.

like image 107
Christian Abella Avatar answered Nov 08 '22 03:11

Christian Abella