save file content-type #1597

This commit is contained in:
Joan Sanchez 2019-07-15 13:16:02 +02:00
parent abe04450f3
commit c658cd3c1f
4 changed files with 13 additions and 6 deletions

View File

@ -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}"`];
};
};

View File

@ -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);

View File

@ -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}`;

View File

@ -17,6 +17,9 @@
"file": {
"type": "string"
},
"contentType": {
"type": "string"
},
"reference": {
"type": "string"
},