我有这样的代码可以集成到我的项目中,
标准代码
var upload = multer({
storage: s3({
dirname: '/',
bucket: 'bucket',
secretAccessKey: 'key',
accessKeyId: 'key',
region: 'us-west-2',
filename: function (req, file, cb) {
cb(null, file.originalname);
}
})
});
app.post('/upload', upload.array('file'), function (req, res, next) {
res.send("Uploaded!");
});
但是我正在使用路由和控制器的结构, 所以我像这样整合,但是没用:
路由:User.js
const express = require("express");
const router = express.Router();
module.exports = function(config) {
var UserController = require("./../controllers/user")(config);
router.post("/upload", UserController.user_upload_file);
return router;
}
控制器:User.js
exports.user_upload_file = upload.array('file',3), function (req, res) {
}
或
upload.array('file',3), exports.user_upload_file = function (req, res) {
}
注意:我不想在route.js中集成变量“上载”