Search code examples
node.jsexpressmultermulter-s3

How to call two different file upload methods in 1 route in express.js


Suppose i have a post request route:

router.post(
  "/create-listing",
  fileUpload.uploadListingPhoto.array("images", 12),
  listingsController.createListing
);

I would like to call a different fileUpload method within the same route, hence i need two different file upload methods for this route. I have accessed the array files via req.files inside the controllers. How do i access the files that will be uploaded by the second method and how do i call the method within the same route? Thank you!


Solution

  • Assuming that the 2nd Method is called after fileUpload.uploadListingPhoto.array("images", 12), you can have a (req,res,next)=>{...your 2nd method... }, chanied before lisitingsController,

    You should still have the acess to the original Incoming request along with its data stream.

    OR

    You can write another Method inside the listingController(or anywhere else) and chain it Provided that you have called and have access to next() in the fileUpload.uploadListingPhoto.array("images", 12), method