Send compressed images from server and uncompress them in client - image

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.

Related

How to optimize image size in mobile development?

I am developing a mobile app on flutter. The app will use about 10 thousand images that are loaded from server and cached. Every image now has about 600x400 resolution, jpeg extension, and size about 100Kb. So the total size will be about 1Gb and I have the following questions:
1) Is there a way to reduce the total size? What image format should I use? Should I compress it on server side and decompress in app if images are loaded one by one?
2) What is the best way to choose image resolution so that the app looks good on both the phone and the tablet?
I won't advice you putting a lot of tasks onto the server side.
The server should be doing the fetching stuffs,
I would suggest you to
Enforce compressions on the client which uploads the image to the server
Pass the images to a third party compressor before they reach your mobile client
The images are of jpeg format, these are easily resized.
This site can help you with the compression..
But I still emphasize you to do it yourself on the client who uploads the image

Include picture in result, JAX-RS, any performance penalty?

As someone on this forum pointed out that send back picture is a bad idea since it have some performance issue. Thus he/she suggest to send back picture's url instead. I'm wondering how could sending back picture have performance impact?
If the picture is rather large, it will take up considerable bandwidth, and also slow down the rest of the JAX-RS framework. Let the client do the work of retrieving the image, it is their bandwidth after all.
If the pictures are hosted elsewhere (on another server), why hog up your bandwidth sending them. After all, while your server is handling hundreds of concurrent requests, each sending a photo, the client only needs to make a few request.
No matter where the pictures are hosted (as long as they are not hosted via JAX-RS), you are putting load on JAX-RS. Other requests will serve slowly because different threads are each trying to send a large file. Overall, this will make your application considerably slower.

How can I compress the JSON content from CouchDB's HTTP responses?

I am making a lot of _all_docs requests to CouchDB's HTTP server. One thing I'm realizing is that the data is not compressed, so this results in large file sizes. Even by using limit and skip, the files can sometimes be 10MB each. That doesn't cause any problems for my app, but it does mean that if a connection to our CouchDB server is slower than our office connection, it will go rather slow.
Is there any way I can enable HTTP compression? I am not referring to attachments - just the JSON files.
Also, I am using Windows Server - not Linux/Unix.
Thanks!
There is no support in CouchDB directly, but it has been requested. (so voice your support there if you want this included)
That being said, there are a number of options you have. First, you can set up nginx as a reverse proxy and allow it to compress (and possibly cache) responses for you. After a quick search, I found this plugin that you install in CouchDB directly.
Another thing is that CouchDB does a pretty solid job of allowing clients to cache reliably. You can leverage this to prevent repeatedly downloading the same large resource.

Caching on web player

I'm creating a runtime obj importer in unity, but I need create a cache system on my web player. I tried "PlayerPrefs" but is to small to store all information. Is there another possibility to store information in client side, close 10MB.
Client-side caching is usually done in memory for speed. If your data can't fit in memory, then you'll need to write it to the local drive or send it to the back-end.
Since the local file storage is unavailable in the Unity3D Web Player, you'll have to either send it to some sort of back-end or develop and in-memory store by hand.
Hope it helps.

Where to store large amounts of images for my site?

If i would want to deploy a site, like ebay, where people will be able to sell something, i would need to store large amounts of images, like many thausends of them and i would need to display about 30 images on some pages.
Normaly i would make a separate server and store them in there, but what else can i do ?
I was trying to store my images on some image hosts like ImageShack, but i have noticed that if i try to request 30 images at same time, some of the images are not showing, looks like imageshack dosnt like to be used this way.
Still there must be some other ways to do it, maybe cloud servers, or other services like imageshack. Does anyone have experience with this ? what would be the best practice beside having a second server ?
Have a file server served by a HTTPD server (e.g. Apache HTTPD) for these static contents.
You can store into the DBMS file locations of the static contents instead of saving as a BLOB this way.
For redirecting traffic, you can store all images (even static files like CSS) in a separate server , like http://staticimg.yourdomain.com . With this way, your web server will be less busy serving download requests.

Resources