A Simple File Cache Server For The Firebase Cloud Storage
Caches files and scales images from the Firebase Cloud Storage. This project aims to reduce the traffic of the Firebase Cloud Storage, which is limited to 1GB per day for free, thus cutting costs.
- Copy the
docker-compose.yml
file into your local directory. - Run
docker compose up -d --build
to start the container. - The server should now run on
0.0.0.0:9998
(you can change the port in thedocker-compose.yml
file)
- Run
docker compose down
to stop the running container - Rebuild and start the container with
docker compose up -d --build
Instead of using https://firebasestorage.googleapis.com/v0/b/<PROJECT>/o/...
, make the request to https://<YOUR-ENDPOINT>/
and provide the query-parameter url
.
e.g.: https://<YOUR-ENDPOINT>/?url=https://firebasestorage.googleapis.com/v0/b/<PROJECT>/o/...
Note, that the access rights to the assets will be preserved. The token
passed with the url
will be validated by firebase, even when the file is cached on the server.
To scale an image from the cloud storage, use the /scale/<size>
endpoint. size
can be <max-width>x<max-height>
or <max-height / max-width>
(single parameter). Note, that the aspect ratio of the image will be preserved. The image will be cached as seen above and gets downscaled on the fly. If the requested url does not lead to an image file, the original asset will be returned.
e.g.:
/scale/500x700?url=https://firebasestorage...
Scales the image to500 x 700
while keeping the aspect ratio./scale/300?url=https://firebasestorage...
Scales the image to300 x 300
By default, all assets will be cache on the host machine in the ./cache
folder relative to docker-compose.yml
file. This can be changed by modifying the docker-compose.yml
file.