In a project I'm working on this I found this issue. For example the uploading size of an image is 192kb But after it uploads it's like 582kb. I'm using React Native and Express JS.
Using express-fileupload
library to handle upload files in expressjs.
Below is the route for the file upload.
router.post(
"/event",
fileUpload({
safeFileNames: true,
preserveExtension: true,
}),
CreateEvent
);
This is the function where I move my image to a folder,
let logo = null;
if (req.files?.logo) {
let file = req.files?.logo;
if (Array.isArray(file)) {
file = file[0];
}
console.log(file?.name);
console.log(file?.size);
logo = `logo_${req.body.name + Date.now() + "." + file?.name.split(".")[1]}`;
const imagePath = path.join(__dirname, "../../uploads", "venue_banners", logo);
file?.mv(imagePath, (err) => {
if (err) {
return res.status(500).json(err);
}
});
}
Also: I'm using form data to upload images in React Native.