Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript change IFormFile to base64string

// Be aware! We are handling only the first <input type="file" /> element
// To avoid errors, it should be placed before this piece of code
var input = document.querySelector('input[type=file]');

// You will receive the Base64 value every time a user selects a file from his device
// As an example I selected a one-pixel red dot GIF file from my computer
input.onchange = function () {
  var file = input.files[0],
    reader = new FileReader();

  reader.onloadend = function () {
    // Since it contains the Data URI, we should remove the prefix and keep only Base64 string
    var b64 = reader.result.replace(/^data:.+;base64,/, '');
    console.log(b64); //-> "R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs="
  };

  reader.readAsDataURL(file);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: spiral traversal clockwise direction js 
Javascript :: call back filter 
Javascript :: white space below image next image 
Javascript :: documentUrlPatterns 
Javascript :: golang read json file 
Javascript :: javascript alert when site page opened not in chrome 
Javascript :: event.target javascript 
Javascript :: javascript replace all with variable 
Javascript :: javascript check item is checkbox 
Javascript :: regex capture group example 
Javascript :: mongoose schema example 
Javascript :: inertia.js 
Javascript :: how to comment in javascript 
Javascript :: Remove escape characters from JSON Data 
Javascript :: asp net core use newtonsoft json 
Javascript :: Filtering an array for unique values 
Javascript :: adding int and string in react props 
Javascript :: how to run react code in visual studio 
Javascript :: gitea 
Javascript :: css defer async 
Javascript :: local time 
Javascript :: console.group in javascript 
Javascript :: white with opacity rgba to hex 
Javascript :: root of any number javascript 
Javascript :: empty array length javascript 
Javascript :: how to write a factorial function in javascript 
Javascript :: mongoose match aggregate 
Javascript :: npm passport-instagram 
Javascript :: dark mode javascript 
Javascript :: javascript get last emlement array 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =