Skip to content

Commit

Permalink
Minio metadata must be encoded to allow special caracters
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien committed Oct 23, 2019
1 parent 5d0f7a3 commit 9b14d39
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions opencti-platform/opencti-graphql/src/database/minio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Minio from 'minio';
import { assoc, isEmpty, concat, map, isNil, sort } from 'ramda';
import querystring from 'querystring';
import mime from 'mime-types';
import conf, { logger } from '../config/conf';
import { getById, now, sinceNowInMinutes } from './grakn';
Expand Down Expand Up @@ -74,7 +75,7 @@ export const loadFile = async filename => {
const stat = await minioClient.statObject(bucketName, filename);
return {
id: filename,
name: stat.metaData.filename,
name: querystring.unescape(stat.metaData.filename),
size: stat.size,
information: '',
lastModified: stat.lastModified,
Expand Down Expand Up @@ -107,17 +108,19 @@ export const filesListing = async (first, category, entity = null) => {
const inExport = await loadExportWorksAsProgressFiles(entity.id);
allFiles = concat(inExport, files);
}
const sortedFiles = sort(
(a, b) => b.lastModified - a.lastModified,
allFiles
);
const sortedFiles = sort((a, b) => b.lastModified - a.lastModified, allFiles);
const fileNodes = map(f => ({ node: f }), sortedFiles);
return buildPagination(first, 0, fileNodes, allFiles.length);
};

export const upload = async (user, category, file, entityId = null) => {
const { createReadStream, filename, mimetype, encoding } = await file;
const metadata = { filename, category, mimetype, encoding };
const metadata = {
filename: querystring.escape(filename),
category,
mimetype,
encoding
};
let entityType = null;
if (entityId) {
const entity = await getById(entityId);
Expand All @@ -131,15 +134,15 @@ export const upload = async (user, category, file, entityId = null) => {
logger.debug(`FileManager > upload file ${filename} by ${user.email}`);
// Upload the file in the storage
return new Promise((resolve, reject) => {
minioClient.putObject(
return minioClient.putObject(
bucketName,
fileDirName,
createReadStream(),
null,
metadata,
err => {
if (err) reject(err);
resolve(loadFile(fileDirName));
if (err) return reject(err);
return resolve(loadFile(fileDirName));
}
);
});
Expand Down

0 comments on commit 9b14d39

Please sign in to comment.