我已经建立了一个上传文件的端点。奇怪的是,端点正在工作,因为文件已上传到我的目标文件夹。我在Postman中收到404错误。我已使用multer上传文件。 Snippet of postman of getting 404
upload.js
const express = require("express");
const router = express.Router();
const multer = require("multer");
const storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, "./uploads/");
},
filename: function(req, file, cb) {
cb(null, file.originalname);
}
});
const upload = multer({
storage,
limits: {
fileSize: 1024 * 1024 * 100
}
});
router.post("/", upload.single("excel"), (err, req, res, next) => {
res.status(200).json({
message: "Uploaded successfully"
});
});
module.exports = router;
script.js
const express = require("express");
const logger = require("morgan");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const upload = require("./upload");
const cors = require("cors");
var xlsx = require("xlsx");
const app = express();
app.use(logger("dev"));
app.use(cors());
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false
})
);
app.use(cookieParser());
//ENDPOINT FOR IMPORTING FILE
app.use("/upload", upload);
app.listen(8080, () => {
console.log("Server is up and running on port", 8080);
});