Categories
JavaScript Answers

How to strip type from JavaScript FileReader base64 string?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.