我正在研究nodejs应用程序i,我必须将上传文件实现到 AWS S3 。我正在尝试实施 multer 来解析文章here之后的multipart / form-data
我正在快递4
这是我的server.ts代码
var express = require('express');
var app = express();
var multer = require('multer');
app.use(multer({
dest: './client2/content/images/uploads',
}))
它给我错误
app.use()需要中间件功能
我想以req.files
的形式访问上传的文件请指导我如何获取文件,以便我可以将其上传到 AWS S3
答案 0 :(得分:1)
这本书似乎已经过时,最好使用npmjs page上的文档。例如:
var express = require('express');
var app = express();
var router = express.Router();
var multer = require('multer');
var upload = multer({ dest: __dirname + '/uploads' });
// single file upload
router.post('/upload', upload.single('test'), function (req, res, next) {
var file = req.file;
console.log(file);
});
// multiple files
router.post('/photos/upload', upload.array('photos', 12), function (req, res, next) {
// req.files is array of `photos` files
// req.body will contain the text fields, if there were any
})