Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Convert file to blob in angular

changeFile(file) {
    return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = () => resolve(reader.result);
        reader.onerror = error => reject(error);
    });
}

uploadFile(event) {
    if (event.target.value) {
        const file = event.target.files[0];
        const type = file.type;
        this.changeFile(file).then((base64: string): any => {
            console.log(base64);
            this.fileBlob = this.b64Blob([base64], type);
            console.log(this.fileBlob)
        });
    } else alert('Nothing')
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: upload and read json file javascript 
Javascript :: toggle class javascript 
Javascript :: show hide more text jquery 
Javascript :: bcd full form in electronics 
Javascript :: sls invoke local 
Javascript :: javascript iterate over divs 
Javascript :: generate guard angular 
Javascript :: react toastify does not have design 
Javascript :: javascript split by backslash 
Javascript :: button disabled javascript 
Javascript :: javascript base 10 to base 2 
Javascript :: export default new class in es6 
Javascript :: mongodb add new field 
Javascript :: javascript change nan to 0 
Javascript :: jquery get aria-label value 
Javascript :: discord.js ban command 
Javascript :: jquery select2 how to make dont close after select 
Javascript :: javascript element text 
Javascript :: javascript check how many times value in array 
Javascript :: find one with specofoc id mongoose 
Javascript :: what is reactjs 
Javascript :: react apexcharts pie props 
Javascript :: jquery check if exist 
Javascript :: import all from javascript 
Javascript :: how to call a function with arguments on event listener javascript 
Javascript :: type of data model mongodb 
Javascript :: count word and space in text javascript 
Javascript :: disable key enter react-hook-form 
Javascript :: jquery on modal close event 
Javascript :: conditionally changing styled components based on props 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =