From a89f00b463b4bc5eca1eeb0b940bdc8fc19249fd Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 19 Jun 2019 07:36:36 +0200 Subject: [PATCH] create path if not exists #1538 --- back/methods/dms/uploadFile.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index 220f944d8..e137ca8ff 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -69,12 +69,22 @@ module.exports = Self => { if (!hasWriteRole) throw new UserError(`You don't have enough privileges`); + // Create final folder if not exists + const dmsType = await models.DmsType.findById(args.dmsTypeId); + await models.Container.getContainer(dmsType.path).catch(async err => { + if (err.code === 'ENOENT') { + await models.Container.createContainer({ + name: dmsType.path + }); + } + }); + + // Upload file to temporary path const uploaded = await models.Container.upload('temp', ctx.req, ctx.result, fileOptions); const files = Object.values(uploaded.files).map(file => { return file[0]; }); - const dmsType = await models.DmsType.findById(args.dmsTypeId); const promises = []; files.forEach(file => {