简体   繁体   中英

Send compressed images from server and uncompress them in client

I'm developing a project using CakePHP 3 for server side and Android for client side. In this project I have to send a lot of images of products from the server to the app. When the app requests the images of a product, the server searches in the database for the urls of the images and send them to the app through a json response. Then, in the app I load the images using NetworkImageView from Volley library.

This process works, but the images are heavy in size, so it consumes a lot of data if you use mobile network like 4g. I can't to lose image quality, so I can't treat the images too much.

What I was thinking was to compress (somehow) the images in server side, send the array of bytes through json and uncompress them in the app, so I could minimize data consumption.

I coudn't find any info for what I described above and I'm not sure if this is the right aproach. Any help would be appreciated.

What I was thinking was to compress (somehow) the images in server side, send the array of bytes through json and uncompress them in the app, so I could minimize data consumption.

JSON will increase and not lower the amount of data that needs to be send for obvious reasons. It's an envelope in your use case and the way JSON works it will add more data. Check the JSON spec.

You want to enable gzip compression on your Webserver ( Nginx here ), check Google for that or superuser.com for more details.

But this won't make a dramatic difference either for mobile use when you send a 20mpx image. I would send small images and only send a lager version when needed, when the user zooms in. Guess that's doable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM