NodeJS req.file。未定义

时间:2021-07-27 11:06:41

标签: node.js

我在第 14 行出现 undefined 错误,req.file

capture

import { Request, Response } from 'express'
import path from 'path'
import Photo from '../models/Photo';

export function getPhoto(req: Request, res: Response){
}

export async function createPhoto(req: Request, res: Response) {
const {title, description} = req.body;

const newPhoto = {
    title: title,
    description: description,
    imagePath: req.file.path
};

const photo = new Photo(newPhoto);
await photo.save();


    return res.json({
        message: 'Foto creada correctamente',
        photo
    })
}

我的 github 上的更多代码:link

我该如何解决?

0 个答案:

没有答案