save file content-type #1597
This commit is contained in:
parent
abe04450f3
commit
c658cd3c1f
|
@ -46,7 +46,7 @@ module.exports = Self => {
|
||||||
if (env && env != 'development') {
|
if (env && env != 'development') {
|
||||||
const pathHash = storageConnector.getPathHash(dms.id);
|
const pathHash = storageConnector.getPathHash(dms.id);
|
||||||
file = {
|
file = {
|
||||||
contentType: 'application/octet-stream',
|
contentType: dms.contentType,
|
||||||
container: pathHash,
|
container: pathHash,
|
||||||
name: dms.file
|
name: dms.file
|
||||||
};
|
};
|
||||||
|
@ -60,6 +60,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
const stream = await models.Container.downloadStream(file.container, file.name);
|
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}"`];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,7 +82,7 @@ module.exports = Self => {
|
||||||
const updatedDmsList = [];
|
const updatedDmsList = [];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const updatedDms = await updateDms(id, dmsTypeId, companyId, warehouseId,
|
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 pathHash = storageConnector.getPathHash(updatedDms.id);
|
||||||
const container = await getContainer(pathHash);
|
const container = await getContainer(pathHash);
|
||||||
|
@ -104,7 +104,7 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
|
|
||||||
async function updateDms(id, dmsTypeId, companyId, warehouseId,
|
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 storageConnector = Self.app.dataSources.storage.connector;
|
||||||
const dms = await Self.findById(id, null, myOptions);
|
const dms = await Self.findById(id, null, myOptions);
|
||||||
const updatedDms = await dms.updateAttributes({
|
const updatedDms = await dms.updateAttributes({
|
||||||
|
@ -113,9 +113,11 @@ module.exports = Self => {
|
||||||
warehouseFk: warehouseId,
|
warehouseFk: warehouseId,
|
||||||
reference: reference,
|
reference: reference,
|
||||||
description: description,
|
description: description,
|
||||||
|
contentType: file.type,
|
||||||
hasFile: hasFile
|
hasFile: hasFile
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
let fileName = file.name;
|
||||||
const oldExtension = storageConnector.getFileExtension(dms.file);
|
const oldExtension = storageConnector.getFileExtension(dms.file);
|
||||||
const newExtension = storageConnector.getFileExtension(fileName);
|
const newExtension = storageConnector.getFileExtension(fileName);
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const addedDms = [];
|
const addedDms = [];
|
||||||
for (const file of files) {
|
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 pathHash = storageConnector.getPathHash(newDms.id);
|
||||||
const container = await getContainer(pathHash);
|
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 models = Self.app.models;
|
||||||
const storageConnector = Self.app.dataSources.storage.connector;
|
const storageConnector = Self.app.dataSources.storage.connector;
|
||||||
const myUserId = ctx.req.accessToken.userId;
|
const myUserId = ctx.req.accessToken.userId;
|
||||||
|
@ -104,9 +104,11 @@ module.exports = Self => {
|
||||||
warehouseFk: args.warehouseId,
|
warehouseFk: args.warehouseId,
|
||||||
reference: args.reference,
|
reference: args.reference,
|
||||||
description: args.description,
|
description: args.description,
|
||||||
|
contentType: file.type,
|
||||||
hasFile: args.hasFile
|
hasFile: args.hasFile
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
let fileName = file.name;
|
||||||
const extension = storageConnector.getFileExtension(fileName);
|
const extension = storageConnector.getFileExtension(fileName);
|
||||||
fileName = `${newDms.id}.${extension}`;
|
fileName = `${newDms.id}.${extension}`;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
"file": {
|
"file": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"contentType": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"reference": {
|
"reference": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue