Skip to content

Commit

Permalink
rename filename
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshbasnet089 committed Mar 8, 2023
1 parent dea1be0 commit ff2f647
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions tapShareBackend/services/multerConfig.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
const multer = require("multer");
var path = require("path");

const fs = require("fs");

function generateFileNumber() {
const fileNumber = Math.floor(10000 + Math.random() * 90000);
return fileNumber;
}

var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "./uploads/");
},
filename: function (req, file, cb) {
let fileNumber = generateFileNumber();
const filePath = path.join(
__dirname,
"uploads",
fileNumber + path.extname(file.originalname)
);
while (fs.existsSync(filePath)) {
fileNumber = generateFileNumber();
}
cb(null, file.originalname);
const filename = file.originalname.replace(/\s+/g, "-");

cb(null, filename);
},
});

Expand Down

1 comment on commit ff2f647

@vercel
Copy link

@vercel vercel bot commented on ff2f647 Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.