Giter Club home page Giter Club logo

Comments (4)

sylvinprogenitive avatar sylvinprogenitive commented on September 12, 2024 2

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

from quickstart-js.

Peripona avatar Peripona commented on September 12, 2024

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. :)

from quickstart-js.

Peripona avatar Peripona commented on September 12, 2024

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);
                });
            }
        );
    }

from quickstart-js.

snoopycp3 avatar snoopycp3 commented on September 12, 2024

thank you so so much~~very appreciate it

from quickstart-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.