Skip to content
VibORM
Esc
navigateopen⌘Jpreview
On this page

Blob

Blob scalar type for binary data like files, images, or encrypted content

Basic Usage

import { s } from "viborm";

s.blob(); // Required Uint8Array
s.blob().nullable(); // Uint8Array | null
s.blob().default(new Uint8Array()); // With default

Blob scalars accept both Uint8Array and Buffer (Node.js). They support .nullable(), .default(), and .map() — but not .array(), .id(), .unique(), or .schema(). See the support matrix and Native Types for column types and MySQL size variants (TINYBLOB through LONGBLOB).

Examples

// File content
const fileContent = s.blob();

// Avatar image (nullable)
const avatar = s.blob().nullable();

// Encrypted data
const encryptedData = s.blob();

Working with Blobs

// Create with Uint8Array
const fileBuffer = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);

await client.file.create({
  data: {
    name: "hello.txt",
    content: fileBuffer,
  },
});

// Read blob data
const file = await client.file.findUnique({
  where: { id: "file_123" },
});

// file.content is Uint8Array
const text = new TextDecoder().decode(file.content);

When to Use Blob

Use Case Recommendation
Small files (<1MB) Blob scalar
Large files (>1MB) Object storage (S3, etc.) + URL scalar
Encryption keys Blob
Thumbnails Blob
Documents Object storage

Was this page helpful?