I have a file encoded in Base64 with a certain file length. How do I get the size in bytes?
Example:
var size= canvas.toDataURL();
console.log(resizeCanvasURL.length);
// -> 132787 base64 length
Each symbol in Base64 encoding holds 6 bits of information. Each symbol in normal file hold 8 bits. Since after decoding you have the same amount of information you need:
normal file size - 1000 bytes
base64 file size - 1333 bytes
The answer from mishik is wrong.
Base64 is filled up with =-chars (to have the right amount of bits). So it should be
var byteLength = parseInt((str).replace(/=/g,"").length * 0.75));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With