Search
 
SCRIPT & CODE EXAMPLE
 

HTML

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
Html :: Remove address underlining formatting from gmail 
Html :: Laravel get the data and display it in the blade html failed 
Html :: html <br , paragraph break or text break 
Html :: how to code cards deck with tab collapse 
Html :: export figma design to html 
Html :: jquery load data 
Html :: form mobile number validation 
Html :: input tag avoid to type 
Html :: site.baseurl page.image_path 
Html :: howdy 
Html :: why html 
Html :: geolocalizacion html5 
Html :: see locked pakages linux 
Html :: html5 mssenger 
Html :: force line label no wrap 
Html :: spinner loader bootstrap 
Html :: how to make a dropdown menu in osu forum 
Html :: how to create a video link in html 
Html :: html beautifier 
Html :: html table with sortable columns 
Html :: data-url html 
Html :: HTML <small Element 
Css :: css hide number input arrows 
Css :: css rotate 90 deg 
Css :: css not first child 
Css :: vertically and horizontally center a fixed div 
Css :: AppDataRoaming pm eact-native.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. 
Css :: 2 lines paragraph 
Css :: how to cover entire div with background image 
Css :: font border css 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =