How to reduce Base64 size?
Asked Answered
L

3

8

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.

Logway answered 27/3, 2015 at 9:14 Comment(6)
you have to Compress image first then after convert into base64.Beadle
you can try zip streams, but there is no guarantee that it will help you, because if the image already has compressed format, there is nothing to do hereSuomi
if image file is too large then create multipart entity HTTP mime web service.Beadle
@JigneshJain I have already compressed image & using Http mine tooLogway
Can an answer be accepted below, VVB?Panarabism
^ I will be happy to undownvote once you have answered.Panarabism
A
8

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
Arlinearlington answered 27/3, 2015 at 9:19 Comment(0)
D
0

Generally speaking, to reduce data size without losing any information you'll need lossless compression. A good starting point there might be Android's built-in zip classes, but you'll still need encoding across the wire.

If it's a captured image, however, changing the parameters of the JPEG compression (or original resolution) will prove far more useful, as the compression you'll get on JPEG-like data which is then base-64'd are likely to be very low.

Dreamy answered 27/3, 2015 at 9:22 Comment(0)
R
0

You need to reduce your actual image size first to be able to reduce your base64 size.

Rabinowitz answered 27/3, 2015 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.