diff --git a/back/methods/dms/downloadFile.js b/back/methods/dms/downloadFile.js index 72090f33b..01ba01b84 100644 --- a/back/methods/dms/downloadFile.js +++ b/back/methods/dms/downloadFile.js @@ -46,7 +46,7 @@ module.exports = Self => { if (env && env != 'development') { const pathHash = storageConnector.getPathHash(dms.id); file = { - contentType: 'application/octet-stream', + contentType: dms.contentType, container: pathHash, name: dms.file }; @@ -60,6 +60,6 @@ module.exports = Self => { const stream = await models.Container.downloadStream(file.container, file.name); - return [stream, file.contentType, `filename="${file.name}"`]; + return [stream, file.contentType, `inline; filename="${file.name}"`]; }; }; diff --git a/back/methods/dms/updateFile.js b/back/methods/dms/updateFile.js index e502c7b94..eaafd7f7d 100644 --- a/back/methods/dms/updateFile.js +++ b/back/methods/dms/updateFile.js @@ -82,7 +82,7 @@ module.exports = Self => { const updatedDmsList = []; for (const file of files) { const updatedDms = await updateDms(id, dmsTypeId, companyId, warehouseId, - reference, description, hasFile, file.name, myOptions); + reference, description, hasFile, file, myOptions); const pathHash = storageConnector.getPathHash(updatedDms.id); const container = await getContainer(pathHash); @@ -104,7 +104,7 @@ module.exports = Self => { }; async function updateDms(id, dmsTypeId, companyId, warehouseId, - reference, description, hasFile, fileName, myOptions) { + reference, description, hasFile, file, myOptions) { const storageConnector = Self.app.dataSources.storage.connector; const dms = await Self.findById(id, null, myOptions); const updatedDms = await dms.updateAttributes({ @@ -113,9 +113,11 @@ module.exports = Self => { warehouseFk: warehouseId, reference: reference, description: description, + contentType: file.type, hasFile: hasFile }, myOptions); + let fileName = file.name; const oldExtension = storageConnector.getFileExtension(dms.file); const newExtension = storageConnector.getFileExtension(fileName); diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index 5d4634aae..b50aaf824 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -70,7 +70,7 @@ module.exports = Self => { const addedDms = []; for (const file of files) { - const newDms = await createDms(ctx, file.name, myOptions); + const newDms = await createDms(ctx, file, myOptions); const pathHash = storageConnector.getPathHash(newDms.id); const container = await getContainer(pathHash); @@ -90,7 +90,7 @@ module.exports = Self => { } }; - async function createDms(ctx, fileName, myOptions) { + async function createDms(ctx, file, myOptions) { const models = Self.app.models; const storageConnector = Self.app.dataSources.storage.connector; const myUserId = ctx.req.accessToken.userId; @@ -104,9 +104,11 @@ module.exports = Self => { warehouseFk: args.warehouseId, reference: args.reference, description: args.description, + contentType: file.type, hasFile: args.hasFile }, myOptions); + let fileName = file.name; const extension = storageConnector.getFileExtension(fileName); fileName = `${newDms.id}.${extension}`; diff --git a/back/models/dms.json b/back/models/dms.json index dc421a7a1..bf6e44311 100644 --- a/back/models/dms.json +++ b/back/models/dms.json @@ -17,6 +17,9 @@ "file": { "type": "string" }, + "contentType": { + "type": "string" + }, "reference": { "type": "string" },