Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Storage Overwriting Files

I have small bug in my program.

I have firebase Storage in my app. I wanna let the user to upload image to the storage.

the thing is when the user uploads image and then tries to upload another image. what the program does it overwrites the image was uploaded before.

what I want is to avoid "overwrite" when the user wants to upload another image. and keep both images in different file

let currentUser = Auth.auth().currentUser
    let StorageRefrenece = Storage.storage().reference()
    let posterImageRef =
        StorageRefrenece.child("posters").child(currentUser!.uid).child("posterOne.jpg")

Thnx

like image 724
Nawaf Avatar asked Jan 30 '19 22:01

Nawaf


People also ask

What is the files page in Firebase?

The Files page provides an overview of the files contained in your Firebase Storage. This can be helpful for visualizing the structure of your Storage instance to verify that your application is working or if you need a convenient way to store just a few files like static images or video content for your application.

How does cloud storage for Firebase save bandwidth?

If the network connection is poor, the client is able to retry the operation right where it left off, saving your users time and bandwidth. Cloud Storage for Firebase stores your files in a Google Cloud Storage bucket, making them accessible through both Firebase and Google Cloud.

Does cloud storage for Firebase SDK return object paths with two s?

The Cloud Storage for Firebase SDK does not return object paths that contain two consecutive / s or end with a /.. For example, consider a bucket that has the following objects: The list operations on items in this bucket will give the following results:

How to add image_picker and Firebase_Storage?

Add firebase_storage, image_picker, path_provider, path and their versions to the dependencies section in your pubspec.yaml file: With the image_picker plugin, we have to do some extra setups for iOS and Android. Go to <your-project>/ios/Runner/Info.plist and add the following between <dict> and </dict>:


1 Answers

That is happening because you're storing them with the same name. In Firebase Storage you're the one in charge to decide the name of the files, there is no ".childByAutoId()".

If you want to have different files, you can create random values to name them, that is well explained here: How does one generate a random number in Apple's Swift language?

Your final code should look like this:

StorageRefrenece.child("posters").child(currentUser!.uid).child(<#Any Random Value#>)
like image 55
Gustavo Vollbrecht Avatar answered Sep 25 '22 22:09

Gustavo Vollbrecht