I have a express-like REST API and I enabled file upload throughout multer.
My file upload-related logic is all addressed within multer, and I'd like to keep it that way. Recently a new file-type was going to be be added to this endpoint (.zip), but I dont really want to save it. I want to be able to re-use multer's logic that was already implemented, but add a precedent step, to pass the files to multer, so it can save them and complete the flow as usual.
What I have so far:
routes.post(
'/upload',
multer(multerConfig).single('file'),
async (req, res) => {
const { path: filePath } = req.file
const file = xlsx.readFile(filePath)
const cells = Object.values(file.Sheets).reduce((accumulator, sheet) => {
const sheetCellsKeys = Object.keys(sheet)
const sortedCellsKeys = sheetCellsKeys
.sort((previousCell, currentCell) => (
previousCell.localeCompare(currentCell, 'en', { numeric: true })
))
const validCellsKeys = sortedCellsKeys.filter((cellKey) => (
/^[A-Z]+[0-9]+$/.test(cellKey)
))
const grouppedCellsKeys = groupBy(validCellsKeys, (cellKey) => (
cellKey.replace(/\D/g, '')
))
return [
...accumulator,
...Object.values(grouppedCellsKeys)
.reduce((cellsAccumulator, cellsKeys) => ([
...cellsAccumulator,
cellsKeys.map((cellKey) => (
sheet[cellKey].v
)),
]), []),
]
}, [])
res.send(cells)
},
)
I want to decompress my zip file, and pass it to multer, as if it's contents was sent to the /process endpoint. Is that possible?