我是新来的。我正在尝试获取StorageUploadTask状态,并在状态为isCompleted&时下载isSuccessful。我在网上找到的示例是旧版本:
StorageUploadTask
isCompleted
isSuccessful
StorageUploadTask uploadTask = ref.putFile(avatarImageFile); Uri downloadUrl = (await uploadTask.future).downloadUrl;
以上不适用于新的firebase_storage插件版本。请帮忙。以下是到目前为止的代码。
firebase_storage
StorageUploadTask uploadTask = ref.putFile(avatarImageFile); StorageReference downRef = uploadTask.lastSnapshot.ref; String downloadUrl = await downRef.getDownloadURL(); if(uploadTask.isComplete) { if(uploadTask.isSuccessful) { print('Upload Successful'); } else if(uploadTask.isCanceled) { print('Upload Cancelled'); } else { print('${uploadTask.lastSnapshot.error}'); } } else if(uploadTask.isInProgress){ print('Upload in Progress'); } else if(uploadTask.isPaused) { print('Upload Paused'); }
最新版本的插件不允许您再使用task.future(),在他们说要使用的文档中,lastSnapshot这对我不起作用。所以,我用了onComplete。这是有效的解决方案:
task.future()
lastSnapshot
onComplete
var ref = FirebaseStorage.instance.ref().child("your_path"); var uploadTask = ref.putFile(avatarImageFile); var storageTaskSnapshot = await uploadTask.onComplete; var downloadUrl = await storageTaskSnapshot.ref.getDownloadURL();