Skip to content

Instantly share code, notes, and snippets.

@dre4success
Created December 9, 2019 14:16
Show Gist options
  • Save dre4success/591643bad61d4eccbc4567d64b89de19 to your computer and use it in GitHub Desktop.
Save dre4success/591643bad61d4eccbc4567d64b89de19 to your computer and use it in GitHub Desktop.
if (Array.isArray(req.files.picture)) {
if (req.files.picture.length > 6)
return res.status(400).json({
status: 400,
message: `You can't upload more than 6 images at once`
});
for (let picture of req.files.picture) {
if (!picture.mimetype.includes('image/'))
return res.status(400).json({
status: 400,
message: `only images allowed for upload`
});
}
let gallery = await Promise.all(
req.files.picture.map(async single => {
let image = await imageUploader(single);
return image;
})
);
let many = await galleryCollection.insertOne({
title: req.body.title,
image: gallery
});
return res.status(200).json({
status: 200,
data: {
many,
message: `Image uploaded successfully`
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment