通过firebase功能上传文件

时间:2019-05-13 17:26:24

标签: node.js firebase express google-cloud-functions

我想使用此代码从firebase函数上传文件。

const app = express();
const busboy = require('connect-busboy');
import * as functions from 'firebase-functions';
app.use(busboy());
app.post('/uploadfile', function(req, res) {
  console.log(req.files);
    req.pipe(req.busboy);
    console.log(req.files);
    req.busboy.on('file', function (fieldname, file, filename) {
        console.log("Uploading: " + filename);
    });
});
exports.boys = functions.https.onRequest(app);

(已编辑) 问题是调用它后,它不会转到.on('file',方法 或者当我使用multer时,req.files或req.files始终是未定义的 有趣的是,此代码可以正常工作。

const app = express();
const busboy = require('connect-busboy');
app.use(busboy());
app.post('/uploadfile', function (req, res) {
    req.pipe(req.busboy);
    req.busboy.on('file', function (fieldname, file, filename) {
        console.log("Uploading: " + filename);
    });
});
app.listen(3000, () => console.log('Server started on port 3000'));

有人有主意吗?

0 个答案:

没有答案