API para upload e download de arquivos em uma base de dados.
openapi: 3.0.1
info:
title: File Storage api
description: Api para fazer upload/dowload de arquivos
contact:
name: gasfgrv
url: https://github.com/gasfgrv
email: [email protected]
version: V1
servers:
- url: http://localhost:8080
description: Generated server url
paths:
/v1/files/upload:
post:
tags:
- files-controler
operationId: uploadFile
requestBody:
content:
multipart/form-data:
schema:
required:
- file
type: object
properties:
file:
type: string
format: binary
responses:
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"417":
description: Expectation Failed
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"413":
description: Payload Too Large
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ResponseMessage'
/v1/files/{id}/download:
get:
tags:
- files-controler
operationId: downloadFile
parameters:
- name: id
in: path
required: true
schema:
type: string
format: uuid
responses:
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"417":
description: Expectation Failed
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"413":
description: Payload Too Large
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"200":
description: OK
content:
application/octet-stream:
schema:
type: array
items:
type: string
format: byte
/v1/files/{id}/details:
get:
tags:
- files-controler
operationId: getFileDetais
parameters:
- name: id
in: path
required: true
schema:
type: string
format: uuid
responses:
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"417":
description: Expectation Failed
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"413":
description: Payload Too Large
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/FileDBDetails'
/v1/files/info:
get:
tags:
- files-controler
operationId: filesInfo
responses:
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"417":
description: Expectation Failed
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"413":
description: Payload Too Large
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ResponseFile'
components:
schemas:
Problem:
type: object
properties:
type:
type: string
format: uri
title:
type: string
status:
type: integer
format: int32
detail:
type: string
instance:
type: string
format: uri
Links:
type: object
additionalProperties:
$ref: '#/components/schemas/Link'
ResponseMessage:
type: object
properties:
message:
type: string
_links:
$ref: '#/components/schemas/Links'
FileDBDetails:
type: object
properties:
id:
type: string
format: uuid
name:
type: string
type:
type: string
_links:
$ref: '#/components/schemas/Links'
ResponseFile:
type: object
properties:
name:
type: string
url:
type: string
type:
type: string
size:
type: integer
format: int64
_links:
$ref: '#/components/schemas/Links'
Link:
type: object
properties:
href:
type: string
hreflang:
type: string
title:
type: string
type:
type: string
deprecation:
type: string
profile:
type: string
name:
type: string
templated:
type: boolean
Para rodar esse projeto, você vai precisar adicionar as seguintes variáveis de ambiente
DB_URL: url de conexão com o banco de dadosDB_USER: usuário do banco de dadosDB_PASS: senha do banco de dadosClone o projeto
git clone [email protected]:gasfgrv/file-storage-api.git
Entre no diretório do projeto
cd file-storage-api
Instale as dependências
mvn clean package -DskipTests
Subir banco de dados
docker-compose up -d
Inicie a aplicação, pode ser pela IDE (Intellij ou Eclipse), ou rodando o seguinte comando:
java \
-Dspring.datasource.url=${DB_URL} \
-Dspring.datasource.username=${DB_USER} \
-Dspring.datasource.password=${DB_PASS} \
-jar target/file-storage-api-0.0.1-SNAPSHOT.jar
Use a collection para ajudar com os endpoints:
Para rodar os testes, rode os seguinte comandos
docker compose up -d
mvn tests
Content type
Image
Digest
sha256:ae7a73e4c…
Size
225 MB
Last updated
over 3 years ago
docker pull gustosilva/file-storage-api