Paul Paul - 16 days ago 10
Objective-C Question

Total upload count is 0 when uploading file to Firebase using iOS SDK

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

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]


We actually create the NSProgress correctly, and update it appropriately for in memory uploads (putData), but aren't getting the file size for file uploads (putFile) since apparently I didn't discover file attributes/they weren't always correct.

I'm working on a fix shortly, for now you can use the NSFileManager.defaultManager().attributesOfItemAtPath(url.path!)[NSFileSize]!.longLongValue workaround to get the file size :)

EDIT (10/10/16): this has been resolved, and if you use the latest version of Firebase Storage, you won't have this problem :)