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 :: while loop javascript 
Javascript :: vuejs chatbot widget 
Javascript :: dependency list useeffect 
Javascript :: useeffect cleanup function 
Javascript :: join javascript array 
Javascript :: javascript object as key 
Javascript :: javascript list comprehension 
Javascript :: how we can set react select required 
Javascript :: how to append an element to an array in javascript 
Javascript :: Return with an "IF" Statement 
Javascript :: js windowresize event 
Javascript :: javascript unit testing frameworks 
Javascript :: static in javascript 
Javascript :: datatable ajax reload 
Javascript :: last item of array js 
Javascript :: vue prop using variable 
Javascript :: how to sort an array 
Javascript :: javascript expression interpolation 
Javascript :: js object 
Javascript :: Requiring express 
Javascript :: google app script 
Javascript :: proptypes for a react component 
Javascript :: reactjs change favicon 
Javascript :: js string encode decode arabic 
Javascript :: ab mob react native expo 
Javascript :: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms 
Javascript :: firstdata payment.js Form Validity 
Javascript :: angular error ng0303 ngForIn 
Javascript :: theme ui currentcolor 
Javascript :: add variable to nth child jquery 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =