How can I save my file image to a folder of the project in javascript?

471 Views Asked by At

I want to save my image to my project's folder, the image that I have in two shapes (base64 or file).

        var base = canvas.toDataURL().replace("data:image/png;base64,", "");

        let file;
        const linkSource = `data:image/png;base64,${base}`;
        await fetch(linkSource)
          .then(res => res.blob())
          .then(blob => {
            file = new File([blob], "test",{ type: "image/png" });
            }
            console.log('base64  ',base);
            console.log('file  ',file);
1

There are 1 best solutions below

0
Pedro Willis-Barbosa On

To speak at a high level, you need a server-side language like Node.js, PHP, Java to run the request through. These can then save files to the back-end's local folders, a folder on your server/computer, or to something like an s3 bucket remotely. All of this will require http request to avoid CORS restrictions.