Skip to content

Instantly share code, notes, and snippets.

@RizkyRajitha
Last active Dec 19, 2019
Embed
What would you like to do?
const express = require("express");
const bp = require("body-parser");
const port = 5000;
const app = express();
const multer = require("multer");
app.use(bp.urlencoded({ extended: false }));
app.use(bp.json());
app.use(require("morgan")("dev"));
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, "./"); // here we specify the destination . in this case i specified the current directory
},
filename: function(req, file, cb) {
console.log(file);
cb(null, file.originalname);// here we specify the file saving name . in this case i specified the original file name
}
});
var uploadDisk = multer({ storage: storage });
app.post("/fileuploaddisk", uploadDisk.single("image"), (req, res) => {
console.log(" file disk uploaded");
res.send("file disk upload success");
});
app.listen(port, () => {
console.log("Express server listning on port " + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment