flask-image-storage is a lightweight, secure backend for temporary image storage. Uploaded images are encrypted on the server and assigned a unique hash for retrieval. Images expire after 5 minutes, ensuring privacy and efficient resource management. The service uses Flask for the API and PostgreSQL for database management.
- Clone the repository:
git clone <repository_url> cd flask-image-storage
- Set the required environment variables:
export POSTGRES_USER=<myuser> export POSTGRES_PASSWORD=<mypassword>
- Start the service with Docker Compose:
docker compose up
- Add API-keys to the database [OPTIONAL]:
#Inside your database in the docker database container: INSERT INTO api_key (api_key, name, timestamp) VALUES ('abcdefg', 'test_user', NOW());
-
Clone the repository:
git clone <repository_url> cd flask-image-storage
-
Install the required Python packages:
pip install -r requirements.txt
-
Start a PostgreSQL container:
docker run -d --name my_postgres_container \ -e POSTGRES_USER=<myuser> \ -e POSTGRES_PASSWORD=<mypassword> \ -e POSTGRES_DB=images \ -p 5432:5432 postgres -
Set the environment variables:
export POSTGRES_USER=<myuser> export POSTGRES_PASSWORD=<mypassword> export HOST=<myhost>
-
Apply database migrations:
flask db upgrade
-
Add API-keys to the database [OPTIONAL]:
#Inside your database in the docker database container: INSERT INTO api_key (api_key, name, timestamp) VALUES ('abcdefg', 'test_user', NOW());
-
Start the development server:
python3 app.py
- Description: Uploads an image, encrypts and stores it in the database, and returns a unique hash for retrieval. If there is no API-key in the database you don't have to provide one. Otherwise you have to add one to the request header. Also triggers cleanup of expired images.
- Request Example:
# No API-key: curl -X POST -F "[email protected]" http://127.0.0.1:5000/upload
# With API-key: curl -X POST -F "[email protected]" -H "api-key: abcdefg" http://127.0.0.1:5000/upload
- Description: Retrieves an image by its unique hash. If the hash corresponds to an expired or non-existent image, an error is returned. Also triggers cleanup.
- Usage Example:
curl http://127.0.0.1:5000/image/<image_hash>
- Description: Deletes all expired images from the database. This endpoint is called automatically during image uploads or retrievals.