[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Bug Report: Image Buffer Corruption After Switching to NeonDB

43 views · 1 like · 3 posts


Fulwing (@fulwing) · 2025-02-07

#### **Describe the Bug**  
After migrating from **Vercel PostgreSQL** to **NeonDB**, I updated my `index.ts` database configuration from:  

```typescript
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  

```typescript
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


Anshuman Bhardwaj (@anshumanb) · 2025-02-07 · ♥ 1

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](https://vercel.com/guides/creating-a-minimal-reproducible-example). That will let us all work together from the same code to figure out what’s going wrong.


system (@system) · 2026-01-20

Hi @fulwing! 🙂

We haven't heard back from you. If you're still stuck, feel free to share any updates, logs, or additional context that might help us assist you better!