I'm trying to create a user with name, email, password and avatar.
the avatar must be uploaded to the cloudninary. after configuring everything, when i tried to upload, i ended up getting this error in my insomnia: "The \"path\" argument must be of type string. Received an instance of Object
here it's my code:
setting up cloudinary
const cloudinary = require('cloudinary');
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_CLOUD_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
then my register function:
exports.registerUser = catchAsyncErrors(async (request, response, next) => {
const result = await cloudinary.v2.uploader.upload(request.body.avatar, {
folder: "avatars",
width: 150,
crop: "scale",
});
const { name, email, password } = request.body;
const user = await User.create({
name,
email,
password,
avatar: {
public_id: result.public_id,
url: result.secure_url,
},
});
sendToken(user, 200, response);
});
Edit: if I send a post request with avatar as string, it works normally