ImageServer with Spring Boot & PostgreSQL.

Erkan Güzeler
echoHub
Published in
3 min readJan 10, 2021

Hi everyone,

In this blog post, I would like to demonstrate you how to run this application developed by me for image server. Storing and serving images is important issue if you develop a product. You need to store images in a file server or db server etc. The good issue of this project is to change width and height your image size with http request. The usage of this app is easy. I will explain the details of the application below.

Table of Contents.

Getting Started

In this blogpost, I have build an application for image serving over http. I used PostgreSQL for storing images. I actually used Spring Boot for backend API. You can easily preview, upload the photos via http, besides, you can adjust the width and height of the photos with REST requests. I will give more information about endpoints of the application below.

Project Structure & Modelling

The project structure of the project like below.

Store Image in PostgreSQL

I have created a Java entity class like below. I used @Lob annotation to store images as byte array. LOB is suitable to store large objects to PostgreSQL. You can examine the source code for other methods in the Image class.

Request has MultipartFile type and I get bytes like file.getBytes(). I also generate a unique name for image when saving time.

Endpoints with Swagger

You can easily list, add and scale images with http requests. Detailed information about requests are like below. If you would like to get information about image you need to use /api/images/. This request give you all information about images. On the other hand, If you use other GET requests, you will get the byte[] array about related image. You can use in any html tags or any related platforms.

Get all image info request

Get all image info response

Upload single image request.

Upload single image response.

Upload multiple image request.

Upload multiple image response.

Docker & Docker Compose

I used Docker & Docker compose for running the application.

DockerFile detail.

Docker Compose file detail.

Build & Run Application

Build docker-compose command.

Run docker-compose

Stop docker-compose

Demo

I hope you enjoy while reading.

Have a nice coding.

Source code available in github.

--

--