Multer 具有 firebase 功能

问题描述 投票:0回答:1

我想使用 firebase 函数进行分段上传。

这是我的代码:

https://pastebin.com/G0PzgtVg

const uploadVideo = Multer({
  storage: MulterStorage,
  limits: {
    fileSize: 5 * 1024 * 1024, // no larger than 5mb, you can change as needed.
  },
  fileFilter: (req, file, cb) => {
    console.log('FILE', file);
    const mimetype = file.mimetype.split('/')[0];
    console.log('FILE', mimetype);

    if (mimetype !== 'video') {
      cb('Error: File is not an video');
    }

    return cb(null, true);
  },
}).single('blob');

但是当我调用函数时出现此错误:

ERROR TypeError: Cannot read property 'filename' of undefined

我在本地主机中没有此错误。

firebase google-cloud-functions multer
1个回答
0
投票

Multer 无法与 Firebase 函数配合使用。相反,您可以使用 express-multipart-file-parser

使用文件解析器:

const fileParser = require('express-multipart-file-parser')

router.use(fileParser);

// or

app.use(fileParser);

解构文件输入:

async function upload(req, res, next) {
    try {

        const {
            fieldname,
            originalname,
            encoding,
            mimetype,
            buffer,
        } = req.files[0]

        console.log('fieldname:', fieldname);
        console.log('originalname:', originalname);
        console.log('encoding:', encoding);
        console.log('mimetype:', mimetype);
        console.log('buffer:', buffer);

        if (typeof req.files[0] != 'undefined') {
           // Do something
        }
      }
}
© www.soinside.com 2019 - 2024. All rights reserved.