Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to overwrite a saved file in firebase storage?

I am dealing with profile pictures in my ionic 1 App. I am searching for a way to update a file in firebase storage such that the download link remains the same. Is it possible or any other way to achieve the required?

like image 433
Mohammad Attaullah Avatar asked Jan 02 '17 09:01

Mohammad Attaullah


People also ask

How do I delete files from storage in Firebase?

To delete a file, first create a reference to that file. Then call the delete() method on that reference, which returns a Promise that resolves, or an error if the Promise rejects.

Do Firebase storage urls expire?

The Firebase Storage token does not expire (see Stack Overflow). Therefore, without any other modifications, our downloadUrl also never expires and remains available.

Can I delete a folder in Firebase storage?

Select the category you want to manage. Select the files you want to remove. To sort files, at the top, tap Filter . After you select your files, at the top, tap Delete .


2 Answers

You can't update the file and maintain the same public download link--it's a different file, so it's assumed that you might want to change the access permissions

Just re-fetch the URL and download the file once it's been updated (it's actually returned in the metadata returned on upload, so you can send it to other apps right after you change it, no need to grab the URL separately):

var file = ... // use the Blob or File API
ref.put(file).then(function(snapshot) {
  var url = snapshot.downloadURL;
});
like image 56
Mike McDonald Avatar answered Sep 20 '22 00:09

Mike McDonald


As the other answer says, basically you cant update the image without it changing the permissions.

BUT, if you change your rules for the path where your image is stored to say

allow read: if true;
allow write: if request.auth != null;

this basically makes it where anyone with the link can see the image. This will let you see the new image from the old download link.

But just know that this also means anybody with this link can see the image, not just people from your app.

like image 37
Dallas Avatar answered Sep 19 '22 00:09

Dallas