I am trying to add a new path to folder I created on cloudinary.
Here is my profilesAPI.js
:
router.post("/upload/image", function (req, res, next) {
const dUri = new Datauri();
const dataUri = (req) =>
dUri.format(path.extname(req.name).toString(), req.data);
if (req.files !== undefined && req.files !== null) {
const { file, id } = req.files;
const newFile = dataUri(file).content;
cloudinary.uploader
.upload(newFile)
.then((result) => {
const imageUrl = result.url;
const data = { id: req.body.id, imageUrl };
updateAvatar(data);
return res.status(200).json({ message: "Success", data: { imageUrl } });
})
.catch((err) =>
res.status(400).json({ message: "Error", data: { err } })
);
} else {
return res.status(400).json({ message: "Error" });
}
});
So right now my url after upload image to cloudinary look like this :
https://res.cloudinary.com/teammateme/image/upload/v1617941466/zwpbarfxvd94olczjjpa.png
and I want to make the url like this:
https://res.cloudinary.com/teammateme/image/upload/v1617941466/UserAvatar/zwpbarfxvd94olczjjpa.png