Skip to content

Commit

Permalink
Upload files using multer
Browse files Browse the repository at this point in the history
  • Loading branch information
codingXpert committed Aug 1, 2022
1 parent e8e6295 commit 3f7220e
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
Binary file added fb15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 119 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"i": "^0.3.7",
"mongodb": "^4.7.0",
"mongoose": "^6.2.9",
"multer": "^1.4.5-lts.1",
"nodemon": "^2.0.18",
"react-toastify": "^9.0.5",
"to": "^0.2.9",
Expand Down
22 changes: 22 additions & 0 deletions uploadFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const express = require("express");
const multer = require("multer");
const app = express();

const upload = multer({
storage: multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads");
},
filename: function (req, file, cb) {
cb(null, file.fieldname +"-"+ Date.now()+ ".jpg");
}
})
}).single("user_file");

// creating route for uploading file
app.post("/uplaod", upload, (req, res) => {
res.send("file uploaded");
});

app.listen(8000);
console.log("Server is running on the port::8000")
1 change: 1 addition & 0 deletions uploads/hint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
all the uploaded files will shown inside this folder

0 comments on commit 3f7220e

Please sign in to comment.