I am trying to load a font file from a local file and turn it into a uri.
Unfortunately, I am having some issues properly reading the file
Here is the function I am constructing:
function fontToDataURI (file_path) {
return fetch(file_path)
.then(resp => resp.blob())
.then(blob => {
console.log(blob.type)
return new Promise(resolve => {
let f = new FileReader();
f.onload = e => resolve(f.result);
f.readAsDataURL(blob);
})
})
.then(dataURL => {
let fontRule = `@font-face {
font-family: "testfont face";
src: url(${dataURL});
}`
return fontRule;
})
Unfortunately, resp.blob() is not able to properly read the mimetype of the file.
When I pass a font file into the function i.e. georgia.tff, I believe I should see a blob type of font/ttf
. Instead, I see the default application/octet-stream
I have used a similar function to pull a .woff2 file from the web and it has recognized the file properly.
Is there a way for me to fix this issue? Thank you!