Converting an image to base64 in angular 2

后端 未结 7 552
醉话见心
醉话见心 2020-11-30 05:31

Converting an image to base64 in angular 2, image is uploaded from local . Current am using fileLoadedEvent.target.result. The problem is, when I send this base64 string thr

7条回答
  •  -上瘾入骨i
    2020-11-30 05:55

    Here is the same code from Parth Ghiya but written in ES6/TypeScript format

    picture: string;
    handleFileSelect(evt){
        const file = evt.target.files[0];
        if (!file) {
            return false;
        }
        const reader = new FileReader();
        
        reader.onload = () => {
            this.picture = reader.result as string;
        };
    
        console.log(btoa(this.picture));
    }
    

提交回复
热议问题