How to reduce the size of Base64?

advertisements

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.


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