r/webdev • u/raiyan_0001 • 2h ago
Discussion Need Help Implementing a Medium-Style Block-Based Article Editor with Cloudinary and MongoDB
Hey, I need some help understanding my development workflow. This might be a bit long, but I want to explain my problem clearly.
I’m a beginner building a small article web app where users can register, log in, and create articles containing both text and images.
I want to implement a block-based architecture, similar to Medium, where users can add text and images in any order. For example, they might write a paragraph, insert an image, write another paragraph, and then insert another image. I’m storing these blocks in an array in my article schema so that their order is preserved.
My main confusion is about image uploads. When a user selects an image, I want to upload it to Cloudinary, receive the image URL, and store that URL inside the corresponding image block in the article.
However, I’m struggling to understand how to connect all these steps. I’ve tried implementing it and asking ChatGPT for help, but I still haven’t understood the workflow properly.
I’d like a beginner-friendly, step-by-step explanation of how to implement this, including how the frontend editor manages the blocks, how the image is uploaded to Cloudinary through the backend, how the returned URL is added to the correct block, and how the complete article is eventually saved to MongoDB.
Please explain the logic behind each step rather than just giving me code, so I can understand the implementation and build it myself.
1
u/Over_Problem_3600 2h ago
give every block an id the moment it's created. that's what made it clock for me, the upload finishes, you find the block by id and set the url
1
u/PrimaryFamous6139 full-stack 1h ago
Give each block a unique ID and type (text or image). When a user selects an image, upload it through your backend to Cloudinary, then update the matching image block with the returned URL using its ID, not its array index. When they click Publish, send the entire blocks array to your backend and save it in MongoDB. Cloudinary stores images, MongoDB stores URLs and block order, and the frontend manages the editor state
1
1
u/c1rno123 1h ago
I'd start with invariants:
- The client owns the state
- The backend is stateless. It validates each request and keeps the DB consistent
The backend (already?) provide atomic operations for adding/removing/shifting blocks.
For images, I'd use a separate Media/Blob entity. Give it a lifecycle such as created → ready.
- The client asks the backend to create a media record.
- The backend creates it with status: "created" and returns an upload URL.
- The client uploads the file using that URL.
- The client tells the backend the upload is complete. The backend verifies it and marks the media record ready.
- The client adds an image block containing the media ID.
When saving the article, the backend checks that each referenced media record exists and is ready.
1
u/web-dev-kev 1h ago
I’m a beginner building a small article web app where users can register, log in, and create articles containing both text and images.
I'd say this is not a beginner project.
Love your enthusiasm, and you're taking the right approach, but what maters here is not how big the app is, but how complex it is.
You're basically building WordPress!
1
u/raiyan_0001 1h ago
Im confused after making login and register
Idk if i ever be able to complete this project but i wanna make it
•
u/web-dev-kev 14m ago
Then I'd stop now.
It's a wonderful goal, and I hope you get there, btu you have no idea of the complexity this involves.
1
u/ExtensionEmotion7136 2h ago
the key is treating each block as its own little unit of data before you ever think about saving the whole article. when a user drops an image in, you fire off the upload right then to your backend, get the url back, and swap the placeholder in that block with the real cloudinary link. only when they hit publish do you string all those blocks together and send the whole array to your db