如何检查图像上传到 Firebase 存储的进度
How to check progress of image upload to Firebase storage
当用户注册我的应用程序时,他们选择个人资料照片、输入姓名、电子邮件和密码。我使用 firebase 使用电子邮件和密码对它们进行身份验证。我正在使用 FIRAuth.auth()?.addAuthStateDidChangeListener
来检测用户身份验证状态的变化。如果用户已通过身份验证,则执行内部代码(此代码将用户发送到下一个 viewController)。问题是在我的数据可以添加到实时数据库和 FirebaseStorage 之前,内部代码就被触发了。有没有办法监视这两个任务何时成功,以便我可以触发视图控制器的更改?谢谢。
Firebase tutorial 关于如何跟踪文件上传到其服务器的进度:
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.
当用户注册我的应用程序时,他们选择个人资料照片、输入姓名、电子邮件和密码。我使用 firebase 使用电子邮件和密码对它们进行身份验证。我正在使用 FIRAuth.auth()?.addAuthStateDidChangeListener
来检测用户身份验证状态的变化。如果用户已通过身份验证,则执行内部代码(此代码将用户发送到下一个 viewController)。问题是在我的数据可以添加到实时数据库和 FirebaseStorage 之前,内部代码就被触发了。有没有办法监视这两个任务何时成功,以便我可以触发视图控制器的更改?谢谢。
Firebase tutorial 关于如何跟踪文件上传到其服务器的进度:
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.