當我將影像上傳到 Firestore 時,將照片路徑發送到資料庫。但我需要在應用程式中發送串列的 URL 型別。如何將照片路徑轉換為 ??URL?

Future uploadFile() async {
if (_photo == null) return;
final fileName = (_photo!.path);
final destination = 'files/$fileName';
try {
final ref =
firebase_storage.FirebaseStorage.instance.ref().child('feedPhotos/');
await ref.putFile(_photo!);
} catch (e) {
print('error occured');
}
}
Tweet tweet = Tweet(
id: id,
text: _tweetText,
image: _photo.toString(),
authorId: postID.toString(),
likes: 0,
retweets: 0,
timestamp: Timestamp.fromDate(DateTime.now(),
),
);
uj5u.com熱心網友回復:
您需要做的是,在將圖片上傳到 Firebase 時,獲取圖片鏈接并將其保存到您的資料庫中,例如
final storageReference =
FirebaseStorage.instance.ref().child("images/myuniquefilename");
await storageReference.putFile(myfile);
String imageUrl = await storageReference.getDownloadURL();
// imageUrl is your download link
//save to firestores
await FirebaseFirestore.instance
.collection("images")
.doc(docId)
.set({
"url":imageUrl
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/497488.html
