Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ts base64 from file

  convertFile(file: File): Observable<string> {
    const result = new ReplaySubject<string>(1);
    const reader = new FileReader();
    reader.readAsBinaryString(file);
    reader.onload = (event) => result.next(btoa(reader.result.toString()));
    return result;
  }
	
this.convertFile(event.target.files[0]).subscribe(base64 => {
	this.base64Output = base64;
});
/// NOTE ///
// The event.target.files is just the File Object e.g. from a
// <input type="file"> form
// you can also create a file with the following command:
var f = new File([""], "filename");


Comment

PREVIOUS NEXT
Code Example
Javascript :: Ternary Expressions in JavaScript 
Javascript :: useref initial value 
Javascript :: javascript infinity 
Javascript :: react using object as prop 
Javascript :: angular flex layout 
Javascript :: react native cors origin 
Javascript :: json.stringify file object return {} 
Javascript :: Check Whether Variable Is String Or Number In JavaScript 
Javascript :: import in react 
Javascript :: using mongoose with node js 
Javascript :: javascript problems 
Javascript :: react native image slider 
Javascript :: how to declare variables javascript 
Javascript :: nodejs cluster 
Javascript :: react autocomplete 
Javascript :: unit testing for react 
Javascript :: AJAX in reload a div container 
Javascript :: javascript multiple startswith 
Javascript :: asyncio.sleep in javascript 
Javascript :: javascript null 
Javascript :: what is node 
Javascript :: add event listeners 
Javascript :: scribbletune 
Javascript :: mongodb mongoose concatenate two values before get 
Javascript :: signup Using codegniter in ajax 
Javascript :: get table schema with knex 
Javascript :: keyboard avoidance view not working on react native 
Javascript :: javascript sensory errors 
Javascript :: python to javascript converter online 
Javascript :: kjkjl 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =