Pular para o conteúdo principal

Arquivos

Gerenciamento de arquivos com upload e download via S3.

Endpoints

MétodoEndpointDescriçãoPermissão
POST/api/v1/filesCriar arquivoFILES_CREATE
GET/api/v1/filesListar arquivosFILES_READ
GET/api/v1/files/:idObter arquivoFILES_READ
POST/api/v1/files/:id/confirm-uploadConfirmar uploadFILES_CREATE
GET/api/v1/files/:id/upload-urlObter URL de uploadFILES_CREATE
GET/api/v1/files/:id/download-urlObter URL de downloadFILES_READ
DELETE/api/v1/files/:idExcluir arquivoFILES_DELETE

Criar Arquivo

POST /api/v1/files

Cria o registro do arquivo e retorna uma URL pré-assinada para upload.

Request

CampoTipoObrigatórioDescrição
namestringSimNome do arquivo
mimeTypestringSimTipo MIME (application/pdf, image/png, image/jpeg)
sizeBytesintegerSimTamanho em bytes
categorystringSimCategoria do arquivo
businessIdstringNãoID da entidade associada
curl -X POST 'https://file-storage.stg.catalisa.app/api/v1/files' \
-H 'Authorization: Bearer SEU_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"name": "documento-identidade.pdf",
"mimeType": "application/pdf",
"sizeBytes": 1048576,
"category": "IDENTITY",
"businessId": "origination-12345"
}'

Response (201 Created)

{
"data": {
"type": "files",
"id": "550e8400-e29b-41d4-a716-446655440000",
"attributes": {
"name": "documento-identidade.pdf",
"mimeType": "application/pdf",
"sizeBytes": 1048576,
"category": "IDENTITY",
"businessId": "origination-12345",
"uploaded": false,
"createdAt": "2024-01-15T10:30:00Z"
}
},
"uploadUrl": "https://bucket.s3.amazonaws.com/files/...?X-Amz-Algorithm=AWS4-HMAC-SHA256&...",
"expiresAt": "2024-01-15T10:45:00Z"
}

Fazer Upload para S3

Apos criar o registro, use a uploadUrl para enviar o arquivo diretamente ao S3.

curl -X PUT 'URL_DE_UPLOAD_RECEBIDA' \
-H 'Content-Type: application/pdf' \
--data-binary @documento-identidade.pdf
Importante
  • O upload deve ser feito diretamente para a URL do S3
  • Use o mesmo Content-Type informado na criação
  • A URL expira em 15 minutos

Confirmar Upload

POST /api/v1/files/:fileId/confirm-upload

Confirma que o upload foi concluido com sucesso.

curl -X POST 'https://file-storage.stg.catalisa.app/api/v1/files/550e8400-e29b-41d4-a716-446655440000/confirm-upload' \
-H 'Authorization: Bearer SEU_TOKEN'

Response (200 OK)

{
"data": {
"type": "files",
"id": "550e8400-e29b-41d4-a716-446655440000",
"attributes": {
"name": "documento-identidade.pdf",
"mimeType": "application/pdf",
"uploaded": true,
"updatedAt": "2024-01-15T10:35:00Z"
}
}
}

Listar Arquivos

GET /api/v1/files

Lista arquivos com suporte a paginação e filtros.

Query Parameters

ParâmetroTipoDescrição
page[number]integerNúmero da página
page[size]integerItens por página
filter[category]stringFiltrar por categoria
filter[businessId]stringFiltrar por businessId
filter[uploaded]booleanFiltrar por status de upload
curl 'https://file-storage.stg.catalisa.app/api/v1/files?filter[category]=IDENTITY&filter[uploaded]=true' \
-H 'Authorization: Bearer SEU_TOKEN'

Response (200 OK)

{
"data": [
{
"type": "files",
"id": "550e8400-e29b-41d4-a716-446655440000",
"attributes": {
"name": "documento-identidade.pdf",
"mimeType": "application/pdf",
"category": "IDENTITY",
"uploaded": true
}
}
],
"meta": {
"totalItems": 25,
"totalPages": 2,
"currentPage": 1
}
}

Obter Arquivo

GET /api/v1/files/:fileId

Obtém detalhes de um arquivo específico.

curl 'https://file-storage.stg.catalisa.app/api/v1/files/550e8400-e29b-41d4-a716-446655440000' \
-H 'Authorization: Bearer SEU_TOKEN'

Obter URL de Upload

GET /api/v1/files/:fileId/upload-url

Obtém uma nova URL pré-assinada para upload (caso a anterior tenha expirado).

curl 'https://file-storage.stg.catalisa.app/api/v1/files/550e8400-e29b-41d4-a716-446655440000/upload-url' \
-H 'Authorization: Bearer SEU_TOKEN'

Response (200 OK)

{
"uploadUrl": "https://bucket.s3.amazonaws.com/files/...?X-Amz-Algorithm=...",
"expiresAt": "2024-01-15T11:00:00Z"
}

Obter URL de Download

GET /api/v1/files/:fileId/download-url

Obtém uma URL pré-assinada para download do arquivo.

curl 'https://file-storage.stg.catalisa.app/api/v1/files/550e8400-e29b-41d4-a716-446655440000/download-url' \
-H 'Authorization: Bearer SEU_TOKEN'

Response (200 OK)

{
"downloadUrl": "https://bucket.s3.amazonaws.com/files/...?X-Amz-Algorithm=...",
"expiresAt": "2024-01-15T11:00:00Z"
}

Excluir Arquivo

DELETE /api/v1/files/:fileId

Remove um arquivo do sistema e do S3.

curl -X DELETE 'https://file-storage.stg.catalisa.app/api/v1/files/550e8400-e29b-41d4-a716-446655440000' \
-H 'Authorization: Bearer SEU_TOKEN'

Response (204 No Content)

Sem corpo de resposta.


Exemplo Completo de Upload

async function uploadDocument(token, file, category, businessId) {
// 1. Criar registro do arquivo
const createResponse = await fetch('https://file-storage.stg.catalisa.app/api/v1/files', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: file.name,
mimeType: file.type,
sizeBytes: file.size,
category,
businessId,
}),
});

const { data, uploadUrl } = await createResponse.json();
const fileId = data.id;

// 2. Upload para S3
const uploadResponse = await fetch(uploadUrl, {
method: 'PUT',
body: file,
headers: {
'Content-Type': file.type,
},
});

if (!uploadResponse.ok) {
throw new Error('Falha no upload para S3');
}

// 3. Confirmar upload
await fetch(
`https://file-storage.stg.catalisa.app/api/v1/files/${fileId}/confirm-upload`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
},
}
);

return fileId;
}

// Uso
const fileId = await uploadDocument(
token,
document.querySelector('input[type="file"]').files[0],
'IDENTITY',
'origination-123'
);

Erros Comuns

CódigoErroDescrição
400VALIDATIONMIME type inválido ou campos ausentes
404NOT_FOUNDArquivo não encontrado
409CONFLICTArquivo já confirmado