0

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 :)

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
mufumade
  • 400
  • 4
  • 16
  • What you're doing here is a little unclear. An observer needs to be added to the uploadTask to monitor it. From the snapshot that's passed in, you can get the percentage complete (and other data) for that task. `let complete = 100.0 * Double(snapshot.progress!.completedUnitCount) / Double(snapshot.progress!.totalUnitCount)`. If you want to combine all of the uploads into one, you would need to combine the three total unit counts together and the completed counts and then divide. See [Monitor Upload Progress](https://firebase.google.com/docs/storage/ios/upload-files#monitor_upload_progress) – Jay Feb 21 '20 at 18:15

1 Answers1

0

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.

xaphod
  • 6,392
  • 2
  • 37
  • 45