How does js canvas compress pictures?

the requirement is to implement compressed upload. Most of them are realized by canvas method on the Internet, so I wrote one after it. But it doesn"t seem to work. After uploading, the downloaded picture is still very large.
the code is as follows

        html5Reader(file, item){

            const reader = new FileReader();
            let Img = new Image();
            let newImageData;
            Img.src =  window.URL.createObjectURL(file);
            Img.onload = (e) => {
                let canvas = document.createElement("canvas");
                let ctx = canvas.getContext("2d");                       
                canvas.width = Img.width;
                canvas.height = Img.height;
                ctx.drawImage(Img, 0, 0, canvas.width, canvas.height);
                newImageData = canvas.toDataURL("image/jpeg", 0.1);
                console.log(newImageData)                    
                this.$set(item, "src", newImageData);
            };                


        },
Mar.19,2021

problem solved.
you need to upload base64 images into ordinary images.

Menu