Ingest Encoded File

User Intent

"I want to upload a file directly from memory/buffer without using a URL"

Operation

  • SDK Method: graphlit.ingestEncodedFile()

  • GraphQL: ingestEncodedFile mutation

  • Entity Type: Content

  • Common Use Cases: File uploads from web forms, email attachments, programmatically generated files, binary data

TypeScript (Canonical)

import { Graphlit } from 'graphlit-client';
import { ContentState, FileTypes } from 'graphlit-client/dist/generated/graphql-types';
import { readFileSync } from 'fs';

const graphlit = new Graphlit();

// Read file from disk
const fileBuffer = readFileSync('/path/to/document.pdf');
const base64Data = fileBuffer.toString('base64');

// Ingest encoded file
const response = await graphlit.ingestEncodedFile(
  'document.pdf',
  base64Data,
  'application/pdf',
  undefined,
  undefined,
  undefined,
  undefined,
  true,
  { id: workflowId },
  [{ id: collectionId }],
  undefined,
  'upload-demo'
);

const contentId = response.ingestEncodedFile.id;
console.log(`File ingested: ${contentId}`);

// Retrieve the content
const content = await graphlit.getContent(contentId);
console.log(`File type: ${content.content.fileType}`);
console.log(`Markdown extracted: ${content.content.markdown?.substring(0, 100)}...`);

Parameters

Required

  • name (string): Filename (including extension)

    • Used to determine file type

    • Should include proper extension (.pdf, .docx, .jpg, etc.)

  • data (string): Base64-encoded file data

    • Binary file content encoded as base64 string

    • No size limit in API, but consider network constraints

  • mimeType (string): MIME type of the file

    • Examples: application/pdf, image/jpeg, text/plain, application/vnd.openxmlformats-officedocument.wordprocessingml.document (DOCX)

    • Must match the actual file type

Optional

  • fileCreationDate (DateTime): Original file creation date

  • fileModifiedDate (DateTime): Original file modification date

  • id (string): Custom ID for the content

  • identifier (string): Custom identifier for deduplication

  • isSynchronous (boolean): Wait for processing to complete

    • Default: false

    • Recommended: true for immediate access to extracted content

  • workflow (EntityReferenceInput): Workflow for extraction/preparation

  • collections (EntityReferenceInput[]): Collections to add content to

  • observations (ObservationReferenceInput[]): Observations to link

  • correlationId (string): For tracking in production systems

Response

Developer Hints

ingestEncodedFile vs ingestUri

Aspect
ingestEncodedFile
ingestUri

Source

File in memory/buffer

URL or file path

Encoding

Requires base64 encoding

No encoding needed

Use Case

File uploads, email attachments

Web scraping, public URLs

Network

Uploads file data to Graphlit

Graphlit downloads from URL

Size Limit

Network/timeout constraints

More efficient for large files

When to Use ingestEncodedFile

Use ingestEncodedFile when:

  • Handling file uploads from users (web forms, mobile apps)

  • Processing email attachments

  • Working with programmatically generated files

  • Files are in memory/buffer

  • No public URL available

Use ingestUri when:

  • File is at a public URL

  • File is very large (>100MB)

  • Want Graphlit to handle download

Base64 Encoding Guide

MIME Type Reference

Common MIME types:

  • PDF: application/pdf

  • Word: application/vnd.openxmlformats-officedocument.wordprocessingml.document

  • Excel: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

  • PowerPoint: application/vnd.openxmlformats-officedocument.presentationml.presentation

  • JPEG: image/jpeg

  • PNG: image/png

  • MP3: audio/mpeg

  • MP4: video/mp4

  • Plain Text: text/plain

Variations

1. Browser File Upload

Handle file uploads in web applications:

2. Email Attachment Processing

Ingest email attachments:

3. Ingesting with Workflow

Apply extraction during upload:

4. Batch File Upload

Upload multiple files efficiently:

5. Ingesting Programmatically Generated Files

Upload files created in code:

Common Issues

Issue: Invalid base64 data error Solution: Ensure data is properly base64 encoded. Remove any data URL prefixes (data:mime;base64,).

Issue: Unsupported MIME type Solution: Check MIME type spelling. Use exact MIME type strings from reference list above.

Issue: File ingested but no text extracted Solution: Ensure file is not corrupted. For scanned PDFs, use a workflow with useVision: true.

Issue: Large file upload times out Solution: For files >50MB, consider using ingestUri with a temporary signed URL instead, or split into chunks.

Issue: Filename has no extension Solution: Add proper extension to name parameter. Graphlit uses extension to determine file type.

Production Example

Email attachment ingestion:

File upload API endpoint pattern:

Last updated

Was this helpful?