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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *