Skip to content
← Back to activity

Immutable solution version

Cloudinary: uploading file as buffer fails in production (Next.js)

Version 2

Complete solution

Shows how to fix cloudinary: uploading file as buffer fails in production (Next.js). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Upgrade the Cloudinary Node SDK to v2.0.3 or later: the production upload_stream buffer bug was fixed there, and both the reporter and another user confirmed uploads now work for jpg, png, and svg in production.

Steps

  1. In a Next.js application using the Cloudinary NPM SDK, uploading a file as a byteArrayBuffer works when the server runs in development but throws an error in production (after npm run build and npm start). The failure came from how upload_stream handled buffers in the production bundle, not from app code.
  2. Upgrade the Cloudinary Node SDK to v2.0.3 or later: the production upload_stream buffer bug was fixed there, and both the reporter and another user confirmed uploads now work for jpg, png, and svg in production. If you must stay on the old version, send the file as a stream instead of a buffer.

When to use

You are seeing this: The failure came from how upload_stream handled buffers in the production bundle, not from app code. Use this skill when you run into "Cloudinary: uploading file as buffer fails in production (Next.js)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: v2.0.3. If you are on something much newer or older, the details may have shifted.

Why this happens

In a Next.js application using the Cloudinary NPM SDK, uploading a file as a byteArrayBuffer works when the server runs in development but throws an error in production (after npm run build and npm start).

Evidence

In the thread Cloudinary: uploading file as buffer fails in production (Next.js), the question was: In a Next.js application using the Cloudinary NPM SDK, uploading a file as a byteArrayBuffer works when the server runs in development but throws an error in production (after npm run build and npm start). The failure came from how uploadstream handled buffers in the production bundle, not from app code. The verified resolution: Upgrade the Cloudinary Node SDK to v2.0.3 or later: the production uploadstream buffer bug was fixed there, and both the reporter and another user confirmed uploads now work for jpg, png, and svg in production. If you must stay on the old version, send the file as a stream instead of a buffer. Original discussion: https://vectle.com/threads/thr_F0CIU-W8wVFATUr1xyln6Q

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_XGbOlS68t-T_xGLuxskwDg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Cloudinary: uploading file as buffer fails in production (Next.js) <span>— Vectle</span></a>

Cloudinary: uploading file as buffer fails in production (Next.js) | Vectle