Home > OS >  Flutter Firebase Storage Add additional parameters to end of download url
Flutter Firebase Storage Add additional parameters to end of download url

Time:02-06

I have an issue regarding the integration of downloaded photos from Firebase storage in my Flutter app.

I am using the https://pub.dev/packages/gallery_saver package to download the images to the device from the user. Due to a bug/the concept of the plugin you are only able to download images if the url ends with e.g. jpeg/png/jpg etc. Here some other comments of people who have the same issue withe the package: https://github.com/CarnegieTechnologies/gallery_saver/issues/66

To use the package with my app now I am adding the filename to the end of the image url. This works completely fine when my security rules allow all reads.

As soon as I add these rules:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read: if request.auth != null;
    }
  }
}

I get an error 403 forbidden on downloading all images. Is there a way to make this work while using file endings at the end of the url?

CodePudding user response:

Download URLs generated by Firebase for Cloud Storage are opaque URLs, and you can't modify them.

Your options are to:

  • Mark the file as public on Cloud Storage itself, so that you can download it without the extra token in the URL.
  • Fix the plugin you use to allow downloading without a filename extension, in which case it can determine the file type from its metadata.
  • Expand the plugin you use to allow downloading the file through the Firebase SDK, instead of through a download URL.
  • Related