Skip to content

Commit

Permalink
allow multiple images formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Sojabio committed Dec 11, 2024
1 parent aeca3a6 commit 756a1b1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions img/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ const app = express();
const port = 4000;
app.use(cors());

const MIME_TYPES: Record<string, string> = {
"image/jpg": "jpg",
"image/jpeg": "jpg",
"image/png": "png"
};


const storage = multer.diskStorage({
destination: function (_req, _file, cb) {
cb(null, path.join(__dirname, "../uploads/"));
},
filename: function (_req, file, cb) {
cb(null, Date.now() + "-" + file.originalname);
const extension = MIME_TYPES[file.mimetype];
cb(null, Date.now() + '.' + extension);

},
});
const upload = multer({ storage: storage });
const upload = multer({ storage: storage });

app.get("/", (_req, res) => {
res.send("Healthcheck Okay");
Expand Down

0 comments on commit 756a1b1

Please sign in to comment.