Skip to content

Commit

Permalink
fixed a bug when using rename on upload files
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Sep 8, 2020
1 parent b64f38a commit d5860bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/api/files/uploadMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { promisify } from 'util';

type multerCallback = (error: Error | null, destination: string) => void;

const rename = promisify(fs.rename);
const copyFile = promisify(fs.copyFile);
const removeFile = promisify(fs.unlink);

const defaultStorage = multer.diskStorage({
filename(_req: Request, file: Express.Multer.File, cb: multerCallback) {
cb(null, generateFileName(file));
Expand All @@ -17,7 +19,8 @@ const defaultStorage = multer.diskStorage({
const move = async (req: Request, filePath: pathFunction) => {
const oldPath = path.join(req.file.destination, req.file.filename);
const newPath = filePath(req.file.filename);
await rename(oldPath, newPath);
await copyFile(oldPath, newPath);
await removeFile(oldPath);
req.file.destination = filePath();
req.file.path = filePath(req.file.filename);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.7.0",
"version": "1.7.1",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"main": "server.js",
"repository": {
Expand Down

0 comments on commit d5860bc

Please sign in to comment.