There seems to be lack of documentation on this topic. I'm trying to upload an image and set it to avatar: { type: Types.CloudinaryImage }
in my Keystone model.
I'm posting content as multipart form data with the following structure: avatar: <raw_data>
. Here is how I handle this in my API:
exports.upload_avatar = function(req, res) {
if (!req.files.avatar) {
console.info('Request body missing');
return res.status(400).json({ message: 'Request body missing', code: 20 });
}
req.current_user.avatar = req.files.avatar;
req.current_user.save();
}
where current_user
is a mongoose model. What I find confusing is how to set my CloudinaryImage
type field to the data I receive in the API.