Image upload, storage and download microservice using Spring boot, MySQL and local storage. This service will be used for the final project of our Webservices course at IT-Högskolan, Gothenburg.
- Create network:
docker network create net
- Create volumes:
docker volume create db-storage
docker volume create file-storage
- Start consul:
docker run -d -p 8500:8500 -p 8600:8600/udp --name=consul --network=net consul agent -server -ui -node=server-1 -bootstrap-expect=1 -client='0.0.0.0'
- Add config file to consul
- Open Consul UI: http://localhost:8500
- Go to Key/Value
- Create the following folder structure:
config/image-service/
- Create a file named:
data (.yml)
- Add the following YML data:
spring:
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
cloud:
consul:
discovery:
register: true
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.cloud.client.hostname}:${random.int[1,999999]}
host: consul
jpa:
hibernate:
ddl-auto: update
datasource:
url: jdbc:mysql://image-database:3306/images
username: user
password: password
server:
port: 8080
- Start database:
docker run -d --name image-database -e MYSQL_ROOT_PASSWORD=root -e 'MYSQL_ROOT_HOST=%' -e MYSQL_DATABASE=images -e MYSQL_USER=user -e MYSQL_PASSWORD=password -p 3306:3306 --network=net -v=db-storage mysql:latest
- Start application:
docker run -d --name image-service -p 8080:8080 --network=net -v=file-storage ghcr.io/patlenlix/image-storage:latest
HTTP-verb | URL | BODY | PRODUCES | HEADER | Info |
---|---|---|---|---|---|
POST | /images | A MultipartFile with the name "multipartFile" and the mediatype set to any | Content-Type: multipart/form-data optional: (URI: uri used to reach endpoint) |
Uploads an image | |
GET | /images/{imageId} | An image file | Downloads an image with id = {imageId} |