`[object: null prototype] { title: 'video', description: '我的视频!'! } on nodejs - multer`。

问题描述 投票:0回答:1
import routes from "./routes";
import multer from "multer";

const multerVideo = multer({ dest: "videos/" });

export const localsMiddleware = (req, res, next) => {
res.locals.siteName = "Webtube";
res.locals.routes = routes;
res.locals.user = {
    isAuthenticated: true,
    id: 1
}
next();
};


--------------------------------------------------------------------------------------------
export const uploadVideo = multerVideo.single("videoFile");

export const postupload = (req, res) => {
const { body } = req;
//To Do: Upload and save Video
console.log(body);
res.render("upload", { pageTitle: "upload" });
};

--------------------------------------------------------------------------------------------
extends layouts/main

block content
    div.form_container
        form(action=`/videos${routes.upload}`, method="post", enctype="multipart/form-data")
            label(for="file") Video File
            input(type="file", id="file", name="videoFile", required=true, 
oninvalid="this.setCustomValidity('please fill out this field')", accept="video/*")
            input(type="text", placeholder="Title", name="title", required=true)
            textarea(name="description", placeholder="Description", required=true)
            input(type="submit", value="Upload Video")

我试过使用multer,但结果是这样的:[object: null prototype] { title: 'video', description: 'My video!' }我也想得到视频文件名,但不能。}我也想得到视频文件名,但不能。有谁知道如何解决这个问题吗?

javascript node.js express multer
1个回答
0
投票

当使用 .single(..) multer 将填入 file-的属性。req-对象,它将包含所有你需要的数据信息。在您的情况下(假设 uploadVideo-当然,中间件是在之前调用的)。)

export const postupload = (req, res) => {
    const { file } = req;
    //To Do: Upload and save Video
    console.log(file.originalname);
    res.render("upload", { pageTitle: "upload" });
};

看看这个 联系 如果你想查看所有的物业在 file-对象:

© www.soinside.com 2019 - 2024. All rights reserved.