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:
ingestEncodedFilemutationEntity 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 dataBinary file content encoded as base64 string
No size limit in API, but consider network constraints
mimeType(string): MIME type of the fileExamples:
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 datefileModifiedDate(DateTime): Original file modification dateid(string): Custom ID for the contentidentifier(string): Custom identifier for deduplicationisSynchronous(boolean): Wait for processing to completeDefault:
falseRecommended:
truefor immediate access to extracted content
workflow(EntityReferenceInput): Workflow for extraction/preparationcollections(EntityReferenceInput[]): Collections to add content toobservations(ObservationReferenceInput[]): Observations to linkcorrelationId(string): For tracking in production systems
Response
Developer Hints
ingestEncodedFile vs 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/pdfWord:
application/vnd.openxmlformats-officedocument.wordprocessingml.documentExcel:
application/vnd.openxmlformats-officedocument.spreadsheetml.sheetPowerPoint:
application/vnd.openxmlformats-officedocument.presentationml.presentationJPEG:
image/jpegPNG:
image/pngMP3:
audio/mpegMP4:
video/mp4Plain 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?