Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert file into base64 in javascript

function getBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
  });
}

var file = document.querySelector('#files > input[type="file"]').files[0];
getBase64(file).then(
  data => console.log(data)
);
Comment

javascript base64 encode file input

var fileInput = document.getElementById('#myInputID');

var reader = new FileReader();
reader.readAsDataURL(fileInput.files[0]);

reader.onload = function () {
	console.log(reader.result);//base64encoded string
};
reader.onerror = function (error) {
	console.log('Error: ', error);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript sort by big amount to small desc 
Javascript :: httpclientmodule is not an angular module 
Javascript :: ajax get form data 
Javascript :: try catch in node js 
Javascript :: mongoose find and update prop 
Javascript :: java password regex 
Javascript :: update formgroup value angular 
Javascript :: update nodejs ubuntu 
Javascript :: beautify json in html 
Javascript :: datatable hide columns 
Javascript :: allow cors express 
Javascript :: string replace javascript 
Javascript :: update angular materia; 
Javascript :: excel datatable 
Javascript :: lottie react 
Javascript :: jquery bind click 
Javascript :: base64 to png nodejs 
Javascript :: convert object to array javascript 
Javascript :: moment get week day 
Javascript :: get size of json object 
Javascript :: scrollview refresh 
Javascript :: usestate array delete 
Javascript :: react router multiple path 
Javascript :: jquery validate checkbox before submit 
Javascript :: new jsonobject java 
Javascript :: npm for node types 
Javascript :: react firebase hooks 
Javascript :: Import file to mongodb database 
Javascript :: how to stop server of react js 
Javascript :: changing color of console log 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =