我想创建一个云端功能端点,可以接受和处理JPEG等图像文件。这是我的代码:
var express = require('express')
var multer = require('multer')
//firebase complains that '/user_code/tmp' is read-only if I use this
//var upload = multer({ dest: 'tmp/' })
var upload = multer({
storage: multer.MemoryStorage,
fileSize: 5 * 1024 * 1024
});
var app = express()
app.post('/image-upload', upload.single('image'), function(req, res, next) {
console.log("request data: " + JSON.stringify(req.data));
console.log("request params: " + JSON.stringify(req.params));
console.log("request query: " + JSON.stringify(req.query));
console.log("request body: " + JSON.stringify(req.body));
console.log("request headers: " + JSON.stringify(req.headers));
console.log("req.file: " + req.file);
console.log("req.files: " + req.files);
res.status(201).send(`My Server Response is ${req.file}`);
});
module.exports.testEndpoint = functions.https.onRequest(app);
出于某种原因,req.file和req.files总是undefined
。但是,req.body似乎确实包含我的图像。我正在使用Postman发送HTTP POST请求。