{
  "name": "Upload documents with validation, deduplication and Postgres storage",
  "nodes": [
    {
      "id": "233a882a-a1bb-4b03-8be1-eca89fc84e1e",
      "name": "Document Upload Form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -1632,
        96
      ]
    },
    {
      "id": "bb4394e9-a3f7-40a7-8481-5fbea0378c30",
      "name": "Webhook Upload",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1632,
        288
      ]
    },
    {
      "id": "a66491fa-d58f-48b5-8821-3ac28abc46e7",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1344,
        208
      ]
    },
    {
      "id": "81c37b00-369b-4699-9a8e-af855ed2c9d3",
      "name": "Check File Size",
      "type": "n8n-nodes-base.if",
      "position": [
        -1120,
        208
      ]
    },
    {
      "id": "92052172-2490-49bc-89cf-1c8105c04178",
      "name": "Check MIME Type",
      "type": "n8n-nodes-base.if",
      "position": [
        -864,
        0
      ]
    },
    {
      "id": "17d16b6e-1923-4281-9e24-9db84d894942",
      "name": "Generate Document Metadata",
      "type": "n8n-nodes-base.code",
      "position": [
        -640,
        -16
      ]
    },
    {
      "id": "129736a4-2406-499f-b776-e7423c12f528",
      "name": "Check for Duplicate",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -480,
        -16
      ]
    },
    {
      "id": "e3d4134d-83fc-4c11-8066-d321e28e9e79",
      "name": "Is Duplicate?",
      "type": "n8n-nodes-base.if",
      "position": [
        -224,
        0
      ]
    },
    {
      "id": "1e2aab77-6bad-4d17-b966-c1f86f85e15c",
      "name": "Insert Document Record",
      "type": "n8n-nodes-base.postgres",
      "position": [
        16,
        320
      ]
    },
    {
      "id": "2a297f88-0611-4429-8539-7ab3c0eebaf0",
      "name": "Return Success Response",
      "type": "n8n-nodes-base.set",
      "position": [
        192,
        320
      ]
    },
    {
      "id": "1cad7e0a-a26f-4b72-aa60-54474755e0a5",
      "name": "Return Duplicate Response",
      "type": "n8n-nodes-base.set",
      "position": [
        96,
        -128
      ]
    },
    {
      "id": "d6807296-11b5-4172-9b57-7cb60f8c48e9",
      "name": "Return Validation Error",
      "type": "n8n-nodes-base.set",
      "position": [
        -656,
        400
      ]
    },
    {
      "id": "0276b453-0b64-4acf-8b78-e0ef46e9a70c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1696,
        -64
      ],
      "parameters": {
        "width": 288,
        "height": 544,
        "content": "## Upload Input\nAccepts document via form or webhook upload."
      }
    },
    {
      "id": "c1796c06-6915-4d94-9217-4536a44c2369",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1376,
        64
      ],
      "parameters": {
        "width": 448,
        "height": 368,
        "content": "## Configuration and Validation\nDefines file size limits, allowed types, and storage settings and Checks file size and MIME type before processing."
      }
    },
    {
      "id": "be61a78f-6df3-43a4-bc7e-cdb06c983faa",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        320
      ],
      "parameters": {
        "width": 320,
        "height": 320,
        "content": "## Error Handling\nReturns error if file validation fails."
      }
    },
    {
      "id": "64a28d6c-b407-4384-acc8-ca034e0f3dc8",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -704,
        -176
      ],
      "parameters": {
        "width": 352,
        "height": 352,
        "content": "## Metadata Generation and Duplicate check \nCreates document ID, hash, and extracts file details and Checks if file already exists using hash comparison."
      }
    },
    {
      "id": "048bb137-e535-4c66-ae29-e6ebf2328235",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -144
      ],
      "parameters": {
        "width": 288,
        "height": 320,
        "content": "## Duplicate Handling\nReturns response if duplicate document is detected."
      }
    },
    {
      "id": "1cbae323-7c3e-4d0e-a77b-33ff6ea437fd",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -272
      ],
      "parameters": {
        "width": 320,
        "height": 320,
        "content": "## Duplicate Handling\nReturns response if duplicate document is detected."
      }
    },
    {
      "id": "55a52db2-941c-426e-839d-d758dd527017",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        144
      ],
      "parameters": {
        "width": 384,
        "height": 384,
        "content": "## Success Response and Record Storage\nStores document metadata in Postgres database and \nReturns success message with document ID."
      }
    },
    {
      "id": "eec948bd-c212-4769-9b3d-3c51ea86ac29",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2288,
        16
      ],
      "parameters": {
        "width": 464,
        "height": 576,
        "content": "## How it works\nThis workflow handles secure document uploads from a form or webhook.\n\nUploaded files are first validated for size and type to ensure they meet defined limits. Once validated, the work"
      }
    }
  ],
  "connections": {
    "Is Duplicate?": {
      "main": [
        [
          {
            "node": "Return Duplicate Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Insert Document Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Upload": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check File Size": {
      "main": [
        [
          {
            "node": "Check MIME Type",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check MIME Type": {
      "main": [
        [
          {
            "node": "Generate Document Metadata",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Duplicate": {
      "main": [
        [
          {
            "node": "Is Duplicate?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document Upload Form": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Document Record": {
      "main": [
        [
          {
            "node": "Return Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Check File Size",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Document Metadata": {
      "main": [
        [
          {
            "node": "Check for Duplicate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}