I am learning Multer and trying to make the most basic app i can to start. I get a 404 GET error when I try to render the response. Here is my code. Thanks for your help.
const express = require('express')
const multer = require('multer')
const path = require('path');
const app = express()
const port = 3001
app.use(express.static(__dirname + 'uploads/'));
app.listen(port, () => {
console.log(`listening on ${port}`)
})
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, 'uploads/');
},
filename: function (req, file, cb) {
cb(null , file.originalname);
}
});
var upload = multer({ storage: storage })
//request
app.post('/upload-profile-pic', upload.single('any_name_you_want'), (req, res) => {
try {
console.log(req.file.path)
res.send(`<img src="${req.file.path}" width="500">`);
}catch(err) {
res.send(400);
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…