在我的 src 目录中,有一个临时文件,使用 multer 我上传了临时文件中的文件,但我无法在 cloudinary 中上传该文件。为什么会这样,请帮帮我,请帮帮我这是我的代码:
我的 src 目录中有一个临时文件,我使用 multer 将文件上传到临时文件中,但无法将文件上传到 cloudinary 中。为什么会这样,请帮帮我,请帮帮我
这是我的代码:
console.log("file detail:", JSON.stringify(req.file))
//output {"fieldname":"avatar","originalname":"Screenshot 2024-07-27 004034.png","encoding":"7bit","mimetype":"image/png","destination":"uploads/","filename":"Screenshot 2024-07-27 004034.png","path":"uploads\Screenshot 2024-07-27 004034.png","size":474631}
if (req.file) {
try {
const result = await cloudinary.v2.uploader.upload(req.file.path, {
folder: "learnify",
width: 250,
height: 250,
gravity: "faces",
crop: "fill",
}).then(result=>console.log('RESULT',result)).catch(error => {
console.error(error.message)});// For result i get undefined
if (result) {
user.avatar.public_id = result.public_id;
user.avatar.secure_url = result.secure_url;
// Remove file from server
fs.rm(`../temp/${req.file.filename}`);
}
} catch (error) {
return next(new AppError("File not upload, please try again", 500));
}
我正在尝试将文件从临时文件上传到 cloudnary......