我正在尝试将艺术家的图像上传到 cloudinary,这是下面的结束路由代码。
const registerArtist = asyncHandler(async (req, res) => {
const { name, gender, state, country, about, avatar } = req.body;
const { file } = req;
console.log(file.path);
const user = await User.findById(req.user._id);
user.artistRequest = "Requested";
const updatedUser = await user.save();
const { secure_url, public_id } = await uploadImageToCloud(file.path);
const artist = new Artist({
user: req.user._id,
name: updatedUser.name,
email: updatedUser.email,
gender: gender,
state: state,
country: country,
about: about,
});
console.log(secure_url, public_id);
artist.avatar = { url: secure_url, public_id };
console.log(artist);
const createdArtist = await artist.save();
res.status(201).json(updatedUser);
});
上传图片到云端 cloudinary 上传后的代码不起作用
import cloudinary from "../cloud/cloud.js";
export const uploadImageToCloud = async (file) => {
const { secure_url: url, public_id } = await cloudinary.uploader.upload(file);
console.log("ff");
console.log(file);
return { url, public_id };
};