Reputation: 311
If I have a reference for Firebase Storage saved as String, like :
String reference = https://firebasestorage.googleapis.com/v0/b/something/o/bucket%2Fp%2FprofilePicture%2Fimage_picker_26.jpg?alt=media&token=something
And this reference points to a picture, how can I get this image from Storage and show it to the user?
I was thinking something like :
Image.network(reference)
But I read on the internet that this isn't safe and I think that this isn't so easy...I should have something like : FirebaseStorage.instance.refFromURL(url)
before calls any widget to show it.
Do you have any suggestion?
Upvotes: 0
Views: 80
Reputation: 83093
I understand that the problem is that the URL returned by the getDownloadURL()
method is a long lived one. This method does not offer the possibility to configure an expiration date to the download URL. It is the same with the JS Client SDK.
However, it is possible with the Admin SDK, see for example the getSignedUrl()
method of the Node.js Admin SDK.
So you could create a Callable Cloud Function, that you call by passing the file reference and which returns a signedURL with an expiration date you choose.
From your Flutter app, you would call this Cloud Function as explained here.
Upvotes: 1
Reputation: 80914
If you want to get the url from the storage after upload then do:
FirebaseStorage storage = FirebaseStorage.instance;
Reference ref = storage.ref().child("folder");
UploadTask uploadTask = ref.putFile(image);
uploadTask.then((res) {
res.ref.getDownloadURL();
});
To display it you can use Image.network()
Upvotes: 0