Firebase Upload images | make use of NSProgress

124 Views Asked by At

I have to upload 3 Images to Firebase. I'd like to monitor the upload progress of all three images via NSProgress.

let currentUploadTask:StorageUploadTask = uploadPath.putData(data, metadata: nil) { (storageMetaData, error) in
                if error != nil{
                    //TODO: Error handling
                }else{
                    print("Upload Finished")
                }
            }

You get to the NSProgress object via currentUploadTask.snapshot.progress And in fact you get the progress percentage if you run currentUploadTask.snapshot.progress.fractionCompleted

Once I combine all "Firebase progresses" to one big progress things fall apart.

let progress:Progress = Progress(totalUnitCount: 3)
progress.addChild(currentUploadTask.snapshot.progress!, withPendingUnitCount: currentUploadTask.snapshot.progress!.totalUnitCount)

// Observe progress.fractionCompleted ----> always 0.0

Thanks in advance :)

1

There are 1 best solutions below

0
xaphod On

I understand what you're trying to do -- I wanted to do it too: you want to use the NSProgress object itself and simply add it as a child of a top-level NSProgress object.

Unfortunately I can see from FirebaseStorage code that this isn't possible:

- (FIRStorageTaskSnapshot *)snapshot {
  @synchronized(self) {
    NSProgress *progress = [NSProgress progressWithTotalUnitCount:self.progress.totalUnitCount];

... because a new NSProgress object is made every time, rather than re-using the existing one. I'll file a feature improvement over on github about it.