You need to use readAsDataUrl():

function getBase64(event) {
   let me = this;
   let file = event.target.files[0];
   let reader = new FileReader();
   reader.readAsDataURL(file);
   reader.onload = function () {
     //me.modelvalue = reader.result;
     console.log(reader.result);
   };
   reader.onerror = function (error) {
     console.log('Error: ', error);
   };
}
Answer from Suresh Kumar Ariya on Stack Overflow
🌐
GitHub
gist.github.com › satyawikananda › fbe4f1fa51c99d27d98e727dd70174e5
Convert image to base64 string from image url using Typescript · GitHub
Convert image to base64 string from image url using Typescript · Raw · toBase64.ts · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Discussions

Convert image path to base64 in typescript - Stack Overflow
output - data:text/html;base64,PCFET0NUWVBFIGh.... my output came like this but the data type is text/html but i want the data type to be image/jpeg ... Your code works as is. When I run that with an imgur url, I get: More on stackoverflow.com
🌐 stackoverflow.com
angular - How can I convert image url to base64 string? - Stack Overflow
I am facing a problem and I need to convert some image, which comes from back as url and convert to base64. For example, how this image url https://cdn.pixabay.com/photo/2015/02/24/15/41/dog-647528... More on stackoverflow.com
🌐 stackoverflow.com
angular - Typescript convert an image url to base64 encoded string fails - Stack Overflow
I would like to convert an image to base 64 format, given its URL. ... getBase64Image(img) { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var dataURL = canvas.toDataURL("image/png"); return dataURL.replace(/^data:image\/(png|jpg);base64... More on stackoverflow.com
🌐 stackoverflow.com
August 21, 2017
Convert image from url to Base64
Using an Image File, I am getting the url of an image, that needs be to send to a webservice. From there the image has to be saved locally on my system. The code I am using: var imagepath = $("# More on stackoverflow.com
🌐 stackoverflow.com
🌐
Staxmanade
staxmanade.com › 2017 › 02 › how-to-download-and-convert-an-image-to-base64-data-url
How to Download and Convert an Image to Base64 Data Url - Developing on Staxmanade
February 26, 2017 - getBase64ImageFromUrl('http://approvaltests.com/images/logo.png') .then(result => testImage.src = result) .catch(err => console.error(err)); As an alternative to base64 encoded FileReader approach above, you can also also use the URL.createObjectURL return URL.createObjectURL(blob);
🌐
npm
npmjs.com › package › image-to-base64
image-to-base64 - npm
const imageToBase64 = require('image-to-base64'); //or //import imageToBase64 from 'image-to-base64/browser'; imageToBase64("path/to/file.jpg") // Path to the image .then( (response) => { console.log(response); // "cGF0aC90by9maWxlLmpwZw==" ...
      » npm install image-to-base64
    
Published: Apr 09, 2021
Version: 2.2.0
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 45792094 › typescript-convert-an-image-url-to-base64-encoded-string-fails
angular - Typescript convert an image url to base64 encoded string fails - Stack Overflow
August 21, 2017 - ... getBase64Image(img) { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var dataURL = canvas.toDataURL("image/png"); return dataURL.replace(/^data:image\/(png|jpg);base64,/, ""); ...
🌐
W3docs
w3docs.com › javascript
How to Convert the Image into a Base64 String Using JavaScript | W3Docs
There are several approaches in JavaScript that can help you with converting the image into a Base64 string. Firstly, create a canvas, then load the image into it and use toDataURL() to get the Base64 representation. In fact, it is a data URL, ...
🌐
xjavascript
xjavascript.com › blog › typescript-image-to-base64
Converting Images to Base64 in TypeScript — xjavascript.com
One effective way to achieve this is by converting images to Base64 strings. Base64 is a binary - to-text encoding scheme that represents binary data in an ASCII string format. TypeScript, being a typed superset of JavaScript, offers a robust environment for handling image to Base64 conversions.
🌐
The Web Dev
thewebdev.info › home › how to get image data as a base64 url in javascript?
How to Get Image Data as a Base64 URL in JavaScript? - The Web Dev
March 20, 2021 - Therefore, when we run getBase64Image ... We can convert an image to a base64 URL by loading the image with the given URL into the canvas and then call toDataURL to convert it to base64....
🌐
GitConnected
levelup.gitconnected.com › how-to-convert-image-to-base64-by-javascript-d110556de37f
How to Convert Image to Base64 with Javascript | by bitbug | Level Up Coding
January 16, 2023 - The following function converts ... call this function // we can wrap this function to Promise-based // function convertImageToBase64Async(imagUrl) { // return new Promise(resovle => convertImageToBase64(imgUrl, resolve)) ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › FileReader › readAsDataURL
FileReader: readAsDataURL() method - Web APIs | MDN
September 18, 2025 - To retrieve only the Base64 encoded string, first remove data:*/*;base64, from the result. ... The Blob or File from which to read. None (undefined). ... const preview = document.querySelector("img"); const fileInput = document.querySelector("input[type=file]"); fileInput.addEventListener("change", previewFile); function previewFile() { const file = fileInput.files[0]; const reader = new FileReader(); reader.addEventListener("load", () => { // convert image file to base64 string preview.src = reader.result; }); if (file) { reader.readAsDataURL(file); } }
🌐
Stack Overflow
stackoverflow.com › questions › 71145474 › how-to-convert-a-image-to-base64-from-a-url-typescript-and-store-it-in-a-string
pdfmake - How to convert a image to base64 from a url typescript and store it in a string - Stack Overflow
February 16, 2022 - getDocumentDefinition() { sessionStorage.setItem('resume', 'name'); return { content: [ { text: 'RESUME', bold: true, fontSize: 20, alignment: 'center', margin: [0, 0, 0, 20] }, { image: getBase64FromUrl('https://localhost:44344/assets/images/logo.png'), width: 100, height: 100, alignment: 'left' }, } }; Here is the function I would like to have in typescript I have tried many diffrent ways to create a base64 stream/string from a url but not of the solution work for me.