I'd like to show users a progress bar when uploading video files recorded within an iOS app to Firebase, so I'm using the observeStatus
feature of the SDK:
// Create a root reference
FIRStorageReference *storageRef = [_storage reference];
// Create a reference to the video
FIRStorageReference *videoRef = [storageRef child:uuidString];
// Upload the file
FIRStorageUploadTask* uploadTask = [videoRef putFile:url metadata:nil];
[uploadTask observeStatus:FIRStorageTaskStatusProgress handler:^(FIRStorageTaskSnapshot *snapshot) {
// A progress event occurred
double percentComplete = 100.0 * (snapshot.progress.completedUnitCount) / (snapshot.progress.totalUnitCount);
NSLog(@"Video with ID %d recording upload progress: %f, completed unit count %lld, total unit count %lld", video.videoId, percentComplete, snapshot.progress.completedUnitCount, snapshot.progress.totalUnitCount);
}];
However, 'Total Unit Count' always seems to be 0, meaning the calculated percent complete goes a bit bonkers with the whole divide-by-0 situation:
Video with ID 3 recording upload progress: inf, completed unit count 163922, total unit count 0
Am I doing something wrong? Following the docs as described here.
[Replicated also in Swift]