【问题标题】:How to use "multer" module in Node.Js apps如何在 Node.Js 应用程序中使用“multer”模块
【发布时间】:2020-02-02 07:47:13
【问题描述】:

我正在观看 Node.Js 教程,但在以下代码中,我无法理解 fileoriginalname 属性/属性的定义和来源?

const multer = require('multer');

const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, 'public/images');
    },

    filename: (req, file, cb) => {
        cb(null, file.originalname)
    }
});

【问题讨论】:

    标签: javascript node.js syntax


    【解决方案1】:

    当您从应用程序上传文件时,例如使用前端多部分表单,multer 会在请求中添加file 属性,具有上传文件的特征。

    Multer 向请求对象添加 (...) 一个或多个文件对象。这 (...) 文件或文件对象包含通过表单上传的文件。 [github doc]

    fileoriginalname 属性,顾名思义,包含用户磁盘上该文件的原始名称。

    当您使用diskStorage 时,multer 在内部将原始请求和file 传递给destinationfilename 函数,因此您可以使用它执行一些特定操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-20
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 2022-01-02
      相关资源
      最近更新 更多