So the realtime database offers me a direct way to reference a node by using its ID. Until now though, I have only seen examples of Firebase storage using the filename to create a reference. What if two files have the same name though? Must I prevent the user from uploading duplicate filenames? The URL is unique but as far as I know you aren't able to create a reference to the file based on it. Is there something I'm missing because this doesn't seem right to me. Thanks for your help.
Asked
Active
Viewed 1.6k times
16
-
Yes. ...almost. (It [looks like it' coming](https://firebase.google.com/docs/storage/web/file-metadata) via metadata MD5). `"at present, setting the md5Hash property on upload doesn't affect the upload, as hash verification is not yet implemented."` – Ronnie Royston Jan 08 '19 at 00:29
1 Answers
25
In Firebase Storage it is up to you to determine the file name when uploading the file. There is no built-in method to generate a unique filename for Firebase Storage (like the push()
method in the database).
If you have two references to the same path, they will be referring to the same file in Firebase Storage.
If you want globally unique filenames, you'll have to generate those yourself. One way would be to use the Firebase Database's push()
method, but you can also use any other GUID-generator for your platform of choice.

Community
- 1
- 1

Frank van Puffelen
- 565,676
- 79
- 828
- 807
-
I see, my plan now is to push() the original filename to a metadata branch in the realtime db along with tags etc., then use the generated key for the filename and upload it to the storage. – ThatBrianDude Nov 22 '16 at 18:17
-
@Frank, I did not see this push() method in Cloud Firestore. Is there any such method for Firestore ? – kernelman Oct 21 '18 at 17:49
-
1See https://stackoverflow.com/questions/50923211/equivalent-of-push-in-firestore – Frank van Puffelen Oct 21 '18 at 18:19
-
-
Is it a good option to store these files using timestamp as there name so no two file names will be same?? – Shivam Singh Aug 03 '20 at 14:23