Skip to content

Commit

Permalink
refactor: delet uuid from image file name
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-komlyk committed Apr 25, 2024
1 parent f036d74 commit 09fc9e0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions apps/server/src/helpers/file-storage.helper.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import multer, { diskStorage } from 'multer';
import * as path from 'path';
import { v4 as uuidv4 } from 'uuid';

import { PUBLIC_FOLDER } from '@constants/routes.constants';

export const FileStorageHelper = (
subfolder: string | undefined | null
subfolder: string | undefined | null,
): multer.StorageEngine => {
return diskStorage({
destination: `./${PUBLIC_FOLDER}/${subfolder ?? ''}`,
filename: (_req, file, cb) => {
const filename = `${path
.parse(file.originalname)
.name.replace(/\s/g, '')}${uuidv4()}`;
.name.replace(/\s/g, '')}`;
const extension = path.parse(file.originalname).ext.toLocaleLowerCase();

cb(null, `${filename}${extension}`);
}
},
});
};

0 comments on commit 09fc9e0

Please sign in to comment.