1

i'am still new in flutter and firebase. I want to ask on how to get the URL file from storage and save it in firestore? this is the code to upload file.

Future uploadFile() async {
if (file == null) return;

final fileName = basename(file.path);
final destination = 'files/$fileName';

task = FirebaseApi.uploadFile(destination, file);
setState(() {});

if (task == null) return;

final snapshot = await task.whenComplete(() {});
final urlDownload = await snapshot.ref.getDownloadURL();

print('Download-Link: $urlDownload');

}

another related class with the upload file

fizahpanda103
  • 49
  • 2
  • 7
  • Hello, you already get the download URL in the code you shared. What did you try for saving it in Firestore? – Renaud Tarnec May 21 '21 at 07:15
  • i dont know how to store the url in the firestore – fizahpanda103 May 21 '21 at 08:20
  • You should have a look at the [documentation](https://firebase.flutter.dev/docs/firestore/usage/#adding-documents) which details, among other, how to add a doc to a Firestore collection. The URL is just a string that you would add to a String field. – Renaud Tarnec May 21 '21 at 08:28
  • Does this answer your question? [Flutter: How Can I Get URL From Firebase Storage In Firestore](https://stackoverflow.com/questions/59160998/flutter-how-can-i-get-url-from-firebase-storage-in-firestore) – Farid Shumbar May 21 '21 at 18:24

0 Answers0