AWS S3 DOWNLOAD - Baixar Arquivo do S3
O que é este Node?
O AWS S3 DOWNLOAD é o node responsável por baixar arquivos armazenados em buckets do Amazon S3 retornando o conteúdo em Base64 com metadados.
Por que este Node existe?
Recuperar arquivos do S3 para processamento é essencial em automações. O S3 DOWNLOAD existe para:
- Recuperar documentos: Baixar PDFs, imagens, arquivos enviados anteriormente
- Processar dados: Pegar arquivos JSON/CSV para análise
- Enviar ao usuário: Recuperar e reenviar documentos solicitados
- Validação: Verificar se um arquivo existe antes de processar
Como funciona internamente?
Quando o S3 DOWNLOAD é executado, o sistema:
- Recebe as credenciais AWS: Access Key ID, Secret Access Key e região
- Localiza o arquivo: Usa bucketName + key para encontrar
- Baixa o objeto: Faz getObject do S3
- Converte para Base64: Transforma Body em string base64
- Retorna metadados: ContentType, Metadata, etc.
- Salva em variáveis: Disponibiliza para próximos nodes
Código interno (aws-executors.service.ts:37-47):
case 'download':
const downloadResult = await s3.getObject({
Bucket: data.bucketName,
Key: data.key,
}).promise();
return {
success: true,
content: downloadResult.Body?.toString('base64'),
contentType: downloadResult.ContentType,
metadata: downloadResult.Metadata,
};
Quando você DEVE usar este Node?
Use S3 DOWNLOAD sempre que precisar recuperar arquivos do S3:
Casos de uso
- Recuperar documentos do usuário: "Baixar o RG enviado anteriormente"
- Processar dados em lote: Baixar CSV/JSON para análise
- Reenviar arquivos: Usuário pede para reenviar um documento
- Validação de existência: Verificar se arquivo foi enviado
- Backup/recuperação: Restaurar dados de backup
Quando NÃO usar S3 DOWNLOAD
- Arquivos muito grandes (>100MB): Use presigned URL ao invés
- Streaming de vídeo: Use CloudFront + S3
- Arquivos públicos: Use presigned URL ou acesso direto
Parâmetros Detalhados
accessKeyId (string, obrigatório)
O que é: Sua AWS Access Key ID (credencial de autenticação).
Onde conseguir: IAM Console → Users → Security credentials → Create access key
Flow completo para testar:
{
"name": "Teste S3 Download - Access Key",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "s3_1",
"type": "aws_s3",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Download S3",
"parameters": {
"operation": "download",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "us-east-1",
"bucketName": "meu-bucket",
"key": "documentos/arquivo.txt"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Mostrar Conteúdo",
"parameters": {
"message": "Arquivo baixado! Tipo: {{s3_contentType}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 700, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "s3_1" },
{ "source": "s3_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Substitua pelos seus dados reais da AWS. O arquivo será baixado.
secretAccessKey (string, obrigatório)
O que é: Sua AWS Secret Access Key (senha da credencial).
Segurança: NUNCA exponha essa chave! Use variáveis de ambiente.
region (string, obrigatório)
O que é: Região AWS onde está o bucket S3.
Valores comuns:
- us-east-1 (Norte da Virgínia)
- us-west-2 (Oregon)
- sa-east-1 (São Paulo)
- eu-west-1 (Irlanda)
Flow completo para testar:
{
"name": "Teste S3 Download - Região",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "s3_1",
"type": "aws_s3",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Download Brasil",
"parameters": {
"operation": "download",
"accessKeyId": "SUA_ACCESS_KEY",
"secretAccessKey": "SUA_SECRET_KEY",
"region": "sa-east-1",
"bucketName": "bucket-brasil",
"key": "uploads/documento.pdf"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Sucesso",
"parameters": {
"message": "Documento baixado da região São Paulo!"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 700, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "s3_1" },
{ "source": "s3_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
bucketName (string, obrigatório)
O que é: Nome do bucket S3 onde o arquivo está armazenado.
Flow completo para testar:
{
"name": "Teste S3 Download - Bucket",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "s3_1",
"type": "aws_s3",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Download",
"parameters": {
"operation": "download",
"accessKeyId": "SUA_ACCESS_KEY",
"secretAccessKey": "SUA_SECRET_KEY",
"region": "us-east-1",
"bucketName": "documentos-clientes",
"key": "rg/cliente-123.jpg"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Confirmar",
"parameters": {
"message": "RG do cliente baixado com sucesso!"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 700, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "s3_1" },
{ "source": "s3_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
key (string, obrigatório)
O que é: Caminho completo do arquivo dentro do bucket.
Formato: pasta1/pasta2/nome-arquivo.extensao
Flow completo para testar:
{
"name": "Teste S3 Download - Key Dinâmica",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Pedir ID",
"parameters": {
"message": "Digite o ID do cliente:",
"variable": "cliente_id"
}
}
},
{
"id": "s3_1",
"type": "aws_s3",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Baixar RG",
"parameters": {
"operation": "download",
"accessKeyId": "SUA_ACCESS_KEY",
"secretAccessKey": "SUA_SECRET_KEY",
"region": "us-east-1",
"bucketName": "documentos",
"key": "rg/cliente-{{cliente_id}}.jpg"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Confirmar",
"parameters": {
"message": "RG do cliente {{cliente_id}} recuperado!"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "s3_1" },
{ "source": "s3_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Digite "123" → busca rg/cliente-123.jpg
Parâmetros
| Campo | Tipo | Obrigatório | Descrição |
|---|---|---|---|
| operation | string | Sim | Deve ser "download" |
| accessKeyId | string | Sim | AWS Access Key ID |
| secretAccessKey | string | Sim | AWS Secret Access Key |
| region | string | Sim | Região AWS (ex: us-east-1) |
| bucketName | string | Sim | Nome do bucket S3 |
| key | string | Sim | Caminho do arquivo no bucket |
Exemplo 1: Recuperar RG do Cliente
Objetivo: Baixar documento de um cliente específico e reenviar.
JSON para Importar
{
"name": "Recuperar e Reenviar RG",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "message_1",
"type": "message",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Pergunta",
"parameters": {
"message": "Deseja receber uma cópia do seu RG? Digite SIM"
}
}
},
{
"id": "input_1",
"type": "input",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Confirmar",
"parameters": {
"message": "Aguardando confirmação...",
"variable": "confirmacao"
}
}
},
{
"id": "condition_1",
"type": "condition",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Verificar SIM",
"parameters": {
"variable": "confirmacao",
"operator": "equals",
"value": "SIM"
}
}
},
{
"id": "s3_1",
"type": "aws_s3",
"position": { "x": 900, "y": 100 },
"data": {
"label": "Baixar RG",
"parameters": {
"operation": "download",
"accessKeyId": "SUA_ACCESS_KEY",
"secretAccessKey": "SUA_SECRET_KEY",
"region": "sa-east-1",
"bucketName": "documentos-clientes",
"key": "rg/{{phone}}.jpg"
}
}
},
{
"id": "media_1",
"type": "media",
"position": { "x": 1100, "y": 100 },
"data": {
"label": "Enviar RG",
"parameters": {
"mediaType": "image",
"mediaUrl": "{{s3_content}}",
"caption": "Aqui está uma cópia do seu RG."
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 1300, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "message_1" },
{ "source": "message_1", "target": "input_1" },
{ "source": "input_1", "target": "condition_1" },
{ "source": "condition_1", "target": "s3_1", "label": "true" },
{ "source": "s3_1", "target": "media_1" },
{ "source": "media_1", "target": "end_1" },
{ "source": "condition_1", "target": "end_1", "label": "false" }
]
}
Saída esperada:
Sistema: Deseja receber uma cópia do seu RG? Digite SIM
Usuário: SIM
Sistema: [envia imagem do RG] Aqui está uma cópia do seu RG.
Exemplo 2: Processar Dados de Backup
Objetivo: Baixar um arquivo JSON de backup e processar.
JSON para Importar
{
"name": "Processar Backup JSON",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Data Backup",
"parameters": {
"variable": "data_backup",
"value": "2025-01-15"
}
}
},
{
"id": "s3_1",
"type": "aws_s3",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Baixar Backup",
"parameters": {
"operation": "download",
"accessKeyId": "SUA_ACCESS_KEY",
"secretAccessKey": "SUA_SECRET_KEY",
"region": "us-east-1",
"bucketName": "backups-relatorios",
"key": "relatorios/{{data_backup}}/vendas.json"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Processar",
"parameters": {
"message": "Backup de {{data_backup}} recuperado! Tipo: {{s3_contentType}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "s3_1" },
{ "source": "s3_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Saída esperada:
Sistema: Backup de 2025-01-15 recuperado! Tipo: application/json
Resposta do Node
{
"success": true,
"content": "SGVsbG8gV29ybGQh",
"contentType": "text/plain",
"metadata": {
"uploaded-by": "user-123",
"document-type": "rg"
}
}
Variáveis criadas:
- {{s3_content}} - Conteúdo do arquivo em Base64
- {{s3_contentType}} - Tipo MIME do arquivo
- {{s3_metadata}} - Metadados customizados (se houver)
Configuração AWS
Permissões IAM Necessárias
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws:s3:::seu-bucket/*"
}
]
}
Boas Práticas
Segurança
SIM: - Use IAM roles com permissões mínimas (apenas GetObject) - Valide se o arquivo existe antes de processar - Use versionamento para recuperar versões antigas - Verifique ContentType antes de processar
NÃO: - Nunca baixe arquivos de buckets não confiáveis - Não processe arquivos muito grandes em memória - Não exponha credenciais no flow
Performance
SIM: - Para arquivos grandes (>10MB), considere presigned URL - Cache arquivos frequentemente acessados - Use CloudFront para distribuir downloads
NÃO: - Não baixe arquivos gigantes (>100MB) diretamente - Não faça download repetido do mesmo arquivo
Tratamento de Erros
SIM: - Verifique se arquivo existe (ListObjects antes) - Trate erro "NoSuchKey" (arquivo não encontrado) - Valide permissões de acesso
Dicas
Conversão Base64: O conteúdo vem em Base64. Use atob() para converter para texto.
Metadados: Use metadata para armazenar informações customizadas (ex: uploaded-by, document-type).
Versionamento: Se versionamento estiver ativo, você pode especificar versionId para baixar versão específica.
Validação: Sempre valide ContentType retornado antes de processar.
Tamanho: Para arquivos >50MB, considere usar presigned URL e fazer download direto.
Próximo Node
→ S3 UPLOAD - Enviar arquivo para S3 → S3 DELETE - Deletar arquivo do S3 → S3 LIST - Listar objetos no bucket