我想在将 iOS 应用中录制的视频文件上传到 Firebase 时向用户显示进度条,因此我使用了 SDK 的 observeStatus 功能:

// 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);
}];

但是,“总单位计数”似乎始终为 0,这意味着计算的完成百分比在整个除以 0 的情况下变得有点疯狂:
Video with ID 3 recording upload progress: inf, completed unit count 163922, total unit count 0

难道我做错了什么?按照 here 中描述的文档进行操作。

[也在 Swift 中复制]

最佳答案

我们实际上正确地创建了 NSProgress,并针对内存上传( putData )适本地更新它,但是没有获得文件上传的文件大小( putFile ),因为显然我没有发现文件属性/它们并不总是正确的。

我很快就会进行修复,现在您可以使用 NSFileManager.defaultManager().attributesOfItemAtPath(url.path!)[NSFileSize]!.longLongValue 解决方法来获取文件大小:)

编辑 (10/10/16):这已解决,如果您使用最新版本的 Firebase Storage,则不会遇到此问题 :)

关于ios - 使用 iOS SDK 将文件上传到 Firebase 时,总上传次数为 0,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37600979/

10-12 00:00
查看更多