convert image to base64 in angularjs

前端 未结 4 1124
自闭症患者
自闭症患者 2020-12-28 20:37

I have a requirement where user will upload their image and i have to convert it into something and send it to .Net REStful service. I am new to angular js. Could someone pl

4条回答
  •  醉话见心
    2020-12-28 20:46

    Code to upload the image in 64 bit in Angularjs

    Html code

    Angular code:

     $scope.uploadFile = function (input) {
                if (input.files && input.files[0]) {
                    var reader = new FileReader();
                    reader.readAsDataURL(input.files[0]);
                    reader.onload = function (e) {
    
                        $('#photo-id').attr('src', e.target.result);                    
                        var canvas = document.createElement("canvas");
                        var imageElement = document.createElement("img");
    
                        imageElement.setAttribute = $('', { src: e.target.result });
                        var context = canvas.getContext("2d");
                        imageElement.setAttribute.load(function()
                        {
                            debugger;
                            canvas.width = this.width;
                            canvas.height = this.height;
    
    
                            context.drawImage(this, 0, 0);
                            var base64Image = canvas.toDataURL("image/png");
    
                            var data = base64Image.replace(/^data:image\/\w+;base64,/, "");
    
                            $scope.model.Logo = data;
                        });
    
    
    
                    }
    
    
                }
            }
    

    for more go to link: http://vikasbishtangular.blogspot.in/2017/04/code-to-upload-image-in-64-bit-in.html

提交回复
热议问题