Skip to content

Instantly share code, notes, and snippets.

@RizkyRajitha
Last active December 19, 2019 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RizkyRajitha/dc4f53afdc4ff9da12d5c2d421b3b6c1 to your computer and use it in GitHub Desktop.
Save RizkyRajitha/dc4f53afdc4ff9da12d5c2d421b3b6c1 to your computer and use it in GitHub Desktop.
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