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?
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://mcmap.net/q/798700/-how-to-get-full-downloadurl-from-uploadtasksnapshot-in-flutter 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);
var urlString = url.toString()
or var urlString = '${url}'
–
Barbell imageStore.path
) –
Barbell "gs://app-db.appspot.com/region/$fileName";
Just thought that I can avoid hardcoding this url. Uri solution worked so thank you –
Cougar flutter clean
. Otherwise I don't know. Doesn't look like the code I posted can produce such an error. –
Barbell url
check this answer: https://mcmap.net/q/505965/-undefined-class-storagereference-when-using-firebase-storage –
Yellowwood 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-
ref
please explain better, I'm having issues getting the Download URL. –
Parkway 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();
With the version of firebase_storage: ^11.0.11. It worked this way:
final FirebaseFirestore firestore = FirebaseFirestore.instance;
final FirebaseStorage storage = FirebaseStorage.instance;
DocumentReference get firestoreRef => firestore.doc('products/$id');
Reference get storageRef => storage.ref().child('products').child(id!);
final UploadTask task = storageRef.child(const Uuid().v1()).putFile(newImage as File);
final TaskSnapshot snapshot = await task.whenComplete(() {});
final String url = await snapshot.ref.getDownloadURL();
updateImages.add(url);
OBS: I'm using package uuid: ^3.0.7 to create a random id for each upload
© 2022 - 2024 — McMap. All rights reserved.