How to calculate the file size from a base64 string in javascript

How to calculate the file size from a base64 string in javascript

A base64 string looks like this:
data:​image/​png;​base64,iVBORw0KGgoAAAANSUhEUg[…]

To calculate the size you have to:

  1. remove the header (data:​image/​png;​base64,)
  2. remove the “=” chars used as padding
  3. multiply for 3/4

The code:

Leave a Reply

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