Storing large images RESTful in the cloud using Google App Engine

In my last article I showed how to store files in the cloud using Google app engine.
Problem there was that the maximum size of the files was 1MB. Not that much for images.

To improve the situation, we just shrink the images with this very simple algorithm by factor 0.9 until the size is less than 1MB:

This FileTransformer class is then just called in the storeFile method of the FileServerResource in the case the file size is large than 1MB:

Remark: So far this only works with JPEG media types, otherwise an exception is raised. Feel free to add different compression cases for other media types (e.g. using GZIP on texts). As I said, it is a good idea to store
the media type 😉