Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Convert base64 string into File type

const url = 'data:image/png;base6....';
fetch(url)
  .then(res => res.blob())
  .then(blob => {
    const file = new File([blob], "File name",{ type: "image/png" })
  })
Comment

Convert file to Base64

handleUpload(event) {
    const file = event.target.files[0];
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => {
        console.log(reader.result);
    };
}
Comment

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

save base 64 string to file

<a [href]="'data:application/octet-stream;base64,' + data | safe" download="excel.xls">Download</a>
Comment

PREVIOUS NEXT
Code Example
Javascript :: sweet alert 2 
Javascript :: JavaScript Error Try Throw Catch 
Javascript :: deploy node app to heroku 
Javascript :: nodejs input 
Javascript :: http_proxy 
Javascript :: use node modules in next.js 
Javascript :: react setstate synchronous 
Javascript :: js arrow vs normal function 
Javascript :: vue on page link or anchor 
Javascript :: return the sum of an array 
Javascript :: how to upgrade nodejs version 
Javascript :: how can i use exact in react router dom v6 
Javascript :: js remove entry 
Javascript :: angular js 
Javascript :: how to take last element of array javascript 
Javascript :: jq json 
Javascript :: useeffect react 
Javascript :: async vs await javascript 
Javascript :: new useSelector 
Javascript :: Uncaught ReferenceError: function is not defined 
Javascript :: typedjs 
Javascript :: react router refreshes page 
Javascript :: replace() in javascript 
Javascript :: giphy javascript github 
Javascript :: tailwind only dropdown 
Javascript :: rotas react com axios 
Javascript :: show mwssage js 
Javascript :: react-resizable-rotatable-draggable 
Javascript :: react native on expo finger print is working bt not in apk 
Javascript :: samuel 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =