How to reduce Base64 size?

19,165

Base-64 is, by definition, a fixed size representation; n bytes binary will always be m characters base-64. The most you can do is remove the final chunk's padding, which will save you a whopping 3 characters maximum.

If you want your payload to be shorter, you could:

  • use a higher base (although you'll need to write the encode/decode manually, and you'll still only be able to get to about base-90 or something, so you won't drastically reduce the size)
  • use a pure binary post body rather than base-anything (this is effectively base-256)
  • have less data
    • by having smaller images
    • or by using compression (note: many image formats are already compressed, so this often won't help)
  • use multiple requests
Share:
19,165
VVB
Author by

VVB

I mainly write code for Android Apps Development. Meanwhile, I keep exploring other programming languages. Also, I love to play around Competitive Programming and prefer reading official documentation for development. LinkedIn: https://in.linkedin.com/pub/vishal-bhandare/41/155/a5b Github: https://github.com/vvbhandare Hackerrank: https://www.hackerrank.com/vvbhandare GeeksForGeeks: https://auth.geeksforgeeks.org/user/Vishal%20Bhandare/profile

Updated on June 25, 2022

Comments

  • VVB
    VVB almost 2 years

    I am new to web service development. I am working on a web service where I need to upload image on server using web service which will be called from an Android application.

    My problem is, when user selects image from Android device and clicks on upload button at that time it generates string using Base64 class file. And its length is more than 3000 characters.

    So, I need to reduce the size of string which is generated using Base64 for image.