Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageReference instead of Location #7

Open
awhitford opened this issue Jun 6, 2020 · 3 comments
Open

StorageReference instead of Location #7

awhitford opened this issue Jun 6, 2020 · 3 comments

Comments

@awhitford
Copy link
Contributor

I like what you've created with FirebaseImage. I am running into a little struggle because I have a StorageReference to my image instead of a fully qualified location (with gs: prefix).

Would it be possible to get an overloaded version that accepts a StorageReference instead of the fully qualified location?

Or is there a good way to translate a StorageReference into a fully qualified location? The getBucket method seems like the translation, but the fact that it is async is a problem because I'm trying to minimize jank, so if I wrap this in a FutureBuilder, it ends up creating jank -- it would be best to have this as part of the ImageProvider since it is already asynchronous. (I'm already using FadeInImage and BlurHash to get a sweet effect.)

@awhitford
Copy link
Contributor Author

(getBucket is not going to yield the location.) I've taken a closer look at the Firebase Storage API and am truly surprised that one can translate a Url to a StorageReference, but not the other way around -- at least easily.

At the application level, using fully qualified Urls for Firebase Storage is problematic if you want to be able to export/import between databases. Hence, I store relative paths and use StorageReference.child to compute the correct image location... Alas, getting that into a location string requires TWO ASYNC calls. 🤦‍♂️

@awhitford
Copy link
Contributor Author

awhitford commented Jun 7, 2020

I managed to get this working fairly well. I reluctantly wrapped a FutureBuilder around the FadeInImage, but since it shows the BlurHash placeholder (same as FadeInImage), it does not create the jank that I was initially worried about.

I still think Firebase Storage needs to improve their API. I opened an issue for them, but I'm not holding my breathe. If they improve their API, I can improve my code.

I still think there is room to revise FirebaseImage to be more StorageReference centric rather than String centric.

@hassanrehman01398
Copy link

You can give storage reference of folder too.
This is how..
Future downloadFile(String duaName) async {
final Directory tempDir = Directory.systemTemp;
final File file = File('${tempDir.path}/$duaName');
final StorageReference ref = FirebaseStorage.instance.ref().child('FileType.image/').child('$duaName');
String url = await ref.getDownloadURL();
final http.Response downloadData = await http.get(url);
var bodyBytes = downloadData.bodyBytes;

 _scaffoldKey.currentState.showSnackBar(
  SnackBar(
    backgroundColor: Colors.white,
    content: Image.memory(
      bodyBytes,
      fit: BoxFit.fill,
    ),
  ),
);

final StorageFileDownloadTask downloadTask = ref.writeToFile(file);
print(downloadTask.toString());

return url;
}

Hope this is helpful for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants