Skip to content

Instantly share code, notes, and snippets.

@oreoluwade
Last active July 12, 2019 16:41
Show Gist options
  • Save oreoluwade/5a43e75e5f5bd25e9435be1bc1bcb1a3 to your computer and use it in GitHub Desktop.
Save oreoluwade/5a43e75e5f5bd25e9435be1bc1bcb1a3 to your computer and use it in GitHub Desktop.
Checks the type and number of files we intend to upload and returns a value based on the specific type
module.exports = input => {
let filePath;
let filename;
let storage = [];
switch (Array.isArray(input)) {
case true:
input.forEach(element => {
filePath = element.path;
filename = element.originalname;
storage.push({ filePath, filename });
});
break;
case false:
if (typeof input === 'object' && Object.keys(input).length) {
Object.values(input).forEach(element => {
filePath = element[0].path;
filename = element[0].originalname;
storage = { filePath, filename };
});
}
break;
default:
break;
}
return storage;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment