Created
December 9, 2019 14:16
-
-
Save dre4success/591643bad61d4eccbc4567d64b89de19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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