Sometimes, we want to strip type from JavaScript FileReader base64 string.
In this article, we’ll look at how to strip type from JavaScript FileReader base64 string.
How to strip type from JavaScript FileReader base64 string?
To strip type from JavaScript FileReader base64 string, we can get the part of the base64 string after the comma.
For instance, we write
const reader: FileReader = new FileReader();
reader.onloaded = (e) => {
const base64String = reader.result.split(",").pop();
};
to get the read file result base64 string from reader.result
.
Then we split it in an array of substrings with comma as the separator with split
.
Finally, we call pop
to get the part of the base64 string without the type.
Conclusion
To strip type from JavaScript FileReader base64 string, we can get the part of the base64 string after the comma.