Skip to content

feat: fix image persistence by migrating from local storage to Cloudinary#216

Open
momanamjad wants to merge 3 commits into
safak:smooth-menufrom
momanamjad:feat/cloudinary-image-storage
Open

feat: fix image persistence by migrating from local storage to Cloudinary#216
momanamjad wants to merge 3 commits into
safak:smooth-menufrom
momanamjad:feat/cloudinary-image-storage

Conversation

@momanamjad
Copy link
Copy Markdown

Problem

The app used multer.diskStorage() to save uploaded images to a
local /images folder on the server. This causes all images to
disappear on every Heroku/Vercel/Render deploy because these
platforms use ephemeral filesystems that reset on restart.

Solution

Replaced local disk storage with Cloudinary. Images now upload
directly to Cloudinary's CDN and a permanent HTTPS URL is stored
in MongoDB instead of a filename.

Changes

  • api/cloudinary.js — new Cloudinary + multer config (new file)
  • api/routes/upload.js — returns Cloudinary URL instead of filename
  • api/index.js — removed local multer/diskStorage, added CORS
  • client/src/pages/Write.js — stores res.data.url as post photo
  • client/src/components/Post.js — renders photo URL directly
  • client/src/pages/SinglePost.js — renders photo URL directly
  • api/.env.example — documents the 3 required Cloudinary env vars

How to test

  1. Add Cloudinary credentials to api/.env
  2. Run backend: cd api && node index.js
  3. Run frontend: cd client && npm start
  4. Register, login, write a post with an image
  5. Image loads from https://res.cloudinary.com/...

Safak and others added 3 commits May 26, 2021 12:07
- Add api/cloudinary.js with CloudinaryStorage config
- Update api/routes/upload.js to return Cloudinary URL
- Update Write.js to store returned Cloudinary URL as photo
- Update Post.js to render photo URL directly
- Update SinglePost.js to render photo URL directly
- Add CORS headers to api/index.js
- Add .env.example with required Cloudinary env var keys
- Remove local multer/diskStorage from index.js

Fixes image persistence on Vercel/Heroku deploys
@momanamjad momanamjad changed the title feat: fix image persistence by migrating from local storage to CloudinaryFeat/cloudinary image storage feat: fix image persistence by migrating from local storage to Cloudinary Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant