// POST - uploadFile
router.post('/uploadFile', function(req,res) {
let uploadType = undefined
const form = formidable({ multiples: true });
form.parse(req, (err, fields, files) => {
// CHECK: error
if (err) {
res.status(500).json("Upload Error 1")
// next(err)
// return
}
console.log('FIELDS', fields)
// PARSE: query
const { parentID, requestorID } = req.query
console.log(typeof files.fileUploader)
// CONFIGURE: upload type
if (Array.isArray(files.fileUploader)) {
uploadType = 'multiple'
res.status(500).json({"Error": "functionality coming soon"})
} else if (typeof files.fileUploader === 'object') {
uploadType = 'single'
} else {
res.status(500).json({ "Error": "Parsed Files: Unknown input type"})
}
// USE MODEL: upload all files to workdrive
model_WorkDrive.uploadFiles(req.tokens[0], uploadType, files.fileUploader, parentID, requestorID)
.then(results => {
res.status(200).json(results)
// res.status(200).json({ fields, files });
})
.catch(err => {
console.error(err)
res.status(500).json(err)
})
})
})