Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[storage] overwriting the same file #6

Closed
archelogos opened this issue May 26, 2016 · 4 comments · Fixed by #8
Closed

[storage] overwriting the same file #6

archelogos opened this issue May 26, 2016 · 4 comments · Fixed by #8

Comments

@archelogos
Copy link
Contributor

Hi there!!

Currently it's not possible to upload more than 1 file which is overwritten every time that another file is uploaded.
It occurs because the ref path is a constant string 'images'.

In /storage/index.html line 88:

var uploadTask = storageRef.child('images').put(file, metadata);

So something like this should fix this problem:

var uploadTask = storageRef.child('images/' + new Date().getTime() + file.name).put(file, metadata);
@sylvinprogenitive
Copy link

sylvinprogenitive commented Jul 27, 2016

thank you so much....u save my life....

@Peripona
Copy link

I am also stuck with this issue, images overwrite themselves with the same name,
I found it very useful. Although one improvement i used Date.now() + file.name instead. :)

@Peripona
Copy link

Here is now the full code in the end

const handleFileUpload = (file) => {
        const storageRef = storage.ref();
        const metadata = {
            customMetadata: {
                size: `${file.size}`,
                title: `${file.name}`
            },
        };
        const uploadTask = storageRef
            .child("images/" + Date.now() + file.name)
            .put(file, metadata);

        uploadTask.on(
            'state_changed',
            (snapshot) => {
                let progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
                console.log("Upload is " + progress + "% done");
                setUpload(progress);
            },
            (error) => {
            },
            () => {
                // Upload completed successfully, now we can get the download URL
                uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => {
                    handleSetImageOnDocument(downloadURL, metadata.customMetadata);
                });
            }
        );
    }

@snoopycp3
Copy link

thank you so so much~~very appreciate it

johnmoody0426 added a commit to johnmoody0426/quickstart-js that referenced this issue Jul 28, 2021
accompany1205 pushed a commit to accompany1205/quickstart-js that referenced this issue May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants