iamshaunjp / firegram

Starting & final course files for the FireGram tutorial (React, Firebase & Framer Motion) on Brad Traversy's YouTube channel.
303 stars 249 forks source link

Image upload issue #6

Open saikatzahid2001 opened 3 years ago

saikatzahid2001 commented 3 years ago

There is a bug in this application. If a user uploads an image with the same name firebase will send the same image twice.

saikatzahid2001 commented 3 years ago

Here is the solution -> const lastIndex = file.name.lastIndexOf('.'); const cutFromExtension = file.name.slice(lastIndex, file.name.length); const newId = Date.now(); const newIdStr = newId.toString() const newFile = newIdStr.concat(cutFromExtension)

instead of -> projectStorage.ref(file.name) use -> projectStorage.ref(newFile)

Hope this bug will be highlighted to help beginners.