const url = 'data:image/png;base6....';
fetch(url)
.then(res => res.blob())
.then(blob => {
const file = new File([blob], "File name",{ type: "image/png" })
})
handleUpload(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
console.log(reader.result);
};
}
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");
<a [href]="'data:application/octet-stream;base64,' + data | safe" download="excel.xls">Download</a>