Bug Report: Image Buffer Corruption After Switching to NeonDB

Describe the Bug

After migrating from Vercel PostgreSQL to NeonDB, I updated my index.ts database configuration from:

import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';
import { config } from 'dotenv';
config({ path: '.env.local' });
export const db = drizzle(sql);

to

import { drizzle } from "drizzle-orm/neon-http";
import { neon } from "@neondatabase/serverless";
import { config } from "dotenv";

config({ path: '.env.local' });

const sql = neon(process.env.DATABASE_URL!);
export const db = drizzle(sql);

Since making this change, I’ve encountered a critical issue:

When storing an image buffer as a BYTEA type in the database, it appears to be saved correctly. However, upon retrieval, the image loses its format and is no longer recognized as a valid image, making it impossible to display.

Expected Behavior

When fetching the stored BYTEA image from the database, it should retain its original format and be properly renderable as an image.

Actual Behavior

After retrieving the stored BYTEA data, it does not retain its original image format and becomes unusable.

Steps to Reproduce

  1. Store an image as a Buffer in a BYTEA column in NeonDB.
  2. Retrieve the stored image from the database.
  3. Attempt to display or process the image—it will not render correctly.

Potential Cause

This issue might be related to how NeonDB’s neon-http driver handles binary data compared to Vercel PostgreSQL’s @vercel/postgres driver. It’s possible that the binary encoding or decoding process is different, causing corruption when retrieving BYTEA data.

Environment

  • Database: NeonDB
  • ORM: Drizzle
  • Node.js Version: v20.18.1
  • Operating System: Win 11 & Ubuntu

Hi @fulwing, welcome to the Vercel Community!

Thanks for sharing your issue in such detail. However, it’d be great if you could please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.

1 Like