Answer the question
In order to leave comments, you need to log in
How to access req.files.location value of upload.any() object?
Good day!
Help to display in the controller the path req.files.location of object upload.any()
routes/app.js
const express = require('express')
const upload = require('../middleware/upload')
const controller = require('../controllers/app')
const router = express.Router()
router.post('/', upload.any(), controller.app)
module.exports = router
const multer = require('multer')
const aws = require('aws-sdk')
const multerS3 = require('multer-s3')
const errorHandler = require('../utils/errorHandler')
const keys = require('../config/keys')
aws.config.update({
secretAccessKey: keys.ACCESS_KEY,
accessKeyId: keys.ACCESS_KEY_ID,
region: keys.REGION
})
const s3 = new aws.S3();
const upload = multer({
storage: multerS3({
s3: s3,
bucket: 'verstesting',
acl: 'public-read',
key: async function (req, file, cb) {
const today = new Date().toISOString().slice(0, 10);
const path = "files.devices/" + req.body.id + "/" + today + "/" + file.originalname + ".jpg";
cb(null, path);
console.log('UPLOAD')
}
})
})
module.exports = upload
module.exports.app = function(req, res){
console.log(req.files.location) // тут то и не возвращает
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question