简体   繁体   中英

How to get full downloadUrl from UploadTaskSnapshot in Flutter?

I correctly receive UploadTaskSnapshot , and the field downloadUrl contains an instance of Uri that parses download link of uploaded file.

How to get storage and downloadUrl as strings?

old

 
 
  
  final uploadTask = imageStore.putFile(imageFile); final url = (await uploadTask.future).downloadUrl;
 
 

update

This answer https://stackoverflow.com/a/52690889/217408 is now the accurate one.

final ref = FirebaseStorage.instance
    .ref()
    .child('path')
    .child('to')
    .child('the')
    .child('image_filejpg');

ref.putFile(imageFile);
// or ref.putData(Uint8List.fromList(imageData));

var url = await ref.getDownloadURL() as String;

or

var url = Uri.parse(await ref.getDownloadURL() as String);

I get downloadUrl from v1.0.3 by the following code.

StorageReference storageReference = _storage.ref().child(path);
StorageUploadTask uploadTask = storageReference.putFile(imageFile);

StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;

String downloadUrl = await taskSnapshot.ref.getDownloadURL();

@DomingoMG it looks like with the latest release they want:

String location = await ref.getDownloadURL();

See https://pub.dartlang.org/packages/firebase_storage#-example-tab-

Update: Nov 2020

onComplete is now removed from the upload task. So, use:

var reference = FirebaseStorage.instance.ref().child("your_path");
await reference.putFile(fileToUpload);
var url = await reference.getDownloadURL();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM