0
3
NRNilberto RodrΓguez Rojas
This file will be loaded as a text file. The code first creates a new Blob object and sets the properties to indicate that the file is an PDF file. It then saves the base64 encoded version of the blob to a new variable called b64. The final step is to use the setBase64 function to set the b64 variable to the base64 encoded blob.
Library: react
// const myblob = new Blob([data], {
// type: 'application/pdf',
// });
// const b64 = await getBase64(myblob);
// setBase64(b64);
const getBase64 = (file: Blob) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
resolve(reader.result);
};
reader.onerror = function (error) {
console.log('Error: ', error);
reject(error);
};
});
};