6

IMAGE COMPRESSION QUESTION

lets say i upload a 100x100 photo from my android device. this image has a size of e.g. 2MB. not a lot. if i compress it then the size will be e.g. 300kB. cool. upload is thunderbolt for any internet speed.

lets consider this case. a random ass motherfucker decides it is cool to upload a 10000x10000 image that has a size e.g. 300MB. compressing this would be e.g. 150MB which is still a lot as fuck for one pic.

heres my question: where should the compression be handled? at backend (REST API server) or client (android image compression library)?

because if i try to send a 150MB pic to the server and their internet sucks but to be fucking honest even the best internet speed would take way too long to upload, is it better to do the compression on the backend or client?

or should i do compression in android? if i should do compression on client then should i;
1) do the compression on the main thread with a progress dialog to wait them until the compression + PLUS the fucking upload is done or
2) do the compression + THE upload in a background thread in which case it can be dangerous for verbose amount of fuckups (internet dies phone explodes etc) and the app crashes

which (one) option of the 2 suboptions from the second parent option branch?

of course this is an extremely unrealistic case, it is possible but thats not my point: my point is WHERE SHOULD THE COMPRESSION (as some kind of universal standard) BE HANDLED AT?

Comments
  • 2
    @irene Are you sure? I think Discord compresses locally before upload. What’re the downsides of doing it like that?
  • 5
    both.

    if you had to choose one, choose backend, but both is ideal.

    get an android library to resize it down to the maximum size, and if someone manages to upload an image bigger than the max size, then reduce it server size.
  • 3
    Sending it to the backend for compression wouldn't be great. Compress from the front end, validate the size from the backend. If the size is too much then reject it
  • 0
    This is what you can do and we do this also,
    In this type of cases,
    You should have a limit of image resolution also,
    Like, you can limit a certain resolution and down scale the image and then compress it.

    And then again add checks on server side also
  • 0
    And for such cases, ask the user if he wants to upload uncompressed photo. Simple as that.
  • 0
    Deny large files, compress everything else at the server
Add Comment