-
Notifications
You must be signed in to change notification settings - Fork 58
Simplify image upload for admin in products #74
Simplify image upload for admin in products #74
Conversation
…implify-image-upload-for-admin-in-products
Code looks ok. Can you share a demo video so that we can see how is it working. Try to upload an image and then show the product page for which you uploaded this image. |
This comment was marked as resolved.
This comment was marked as resolved.
Thanks for bearing with me @s-vamshi I'll summarize what you've done. If I am wrong correct me.
Am I right? I have some questions to address.
You have used the try-catch block. It will be nice if you simulate an error and add a screenshot if possible. |
@roopeshsn |
No simulating Cloudinary error is not required. Is there any way to change the error message meaningful? |
Yes i am working on it. |
Also, have you taken care of when the admin wants to edit the product image? |
No, I am asking about what will be the case if the user selects a video or a text file. |
NO |
It will not upload to cloud hence image Src state will be an empty string |
Yes, we need to take care of all the edge cases. |
As of now, I will merge the PR up to what you've done. Y After that you can work on the edit product route. What's your thought? |
backend/routes/uploadRoutes.js
Outdated
@@ -1,20 +1,25 @@ | |||
const path = require('path') | |||
const express = require('express') | |||
const multer = require('multer') | |||
const cloudinary = require("cloudinary").v2 | |||
const { CloudinaryStorage } = require("multer-storage-cloudinary") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What did this package do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of storage to local system using multer we are using a similar package called multer storage cloudinary to store images directly in cloud.
And to upload images we need api keys so we need to use cloudinary package.
backend/routes/uploadRoutes.js
Outdated
null, | ||
`${file.fieldname}-${Date.now()}${path.extname(file.originalname)}`, | ||
) | ||
cloudinary.config({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a config folder in the backend. Is it possible to change the config code there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yes can i make all this changes tomorrow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. Take your own time. I highly encourage you to contribute in your free time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roopeshsn I have moved cloud config to db/config.
|
@roopeshsn This is the change i have made in edit product page. Is it ok? |
There is no need to render the previous product image. |
@roopeshsn removed previous product image. |
Yes, this bug persists. If possible could you create an issue for the same? |
Ok. I will create an issue and can you review my PR ? |
How we can handle this? If I am a product is getting updated with a new image and then the old image should get deleted in Cloudinary. Would like to know your thoughts. |
So updating a product with a new image is working fine right? |
Ya this is a great idea I will start working on it. |
Yes |
Wait, I will merge this PR then you can create a new issue and work on that. The code is not formatted properly. We have a prettier command to format recursively. Check the package.json file. |
Appreciate your work @s-vamshi |
@roopeshsn should i start working on this feature or should i wait until 404 page feature gets merged? |
Simplifying product image upload process for admins by using multer-storage-cloudinary npm package