From cd9296b37bca030aa1c56e4782a28f1ce79a24f8 Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Wed, 9 Sep 2020 10:18:22 +0200 Subject: [PATCH] Fix replace media (#7787) * Fixes #7776 Signed-off-by: soupette * Fix PR feedback Signed-off-by: soupette --- .../admin/src/components/EditForm/index.js | 4 +++- .../admin/src/utils/createFileToDownloadName.js | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js b/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js index aa91b98955..c0a3e70811 100644 --- a/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js +++ b/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js @@ -135,7 +135,9 @@ const EditForm = forwardRef( }; const handleChange = ({ target: { files } }) => { - onChange({ target: { name: 'file', value: files[0] } }); + if (files[0]) { + onChange({ target: { name: 'file', value: files[0] } }); + } }; const handleClick = async () => { diff --git a/packages/strapi-plugin-upload/admin/src/utils/createFileToDownloadName.js b/packages/strapi-plugin-upload/admin/src/utils/createFileToDownloadName.js index a2509299cf..5844add946 100644 --- a/packages/strapi-plugin-upload/admin/src/utils/createFileToDownloadName.js +++ b/packages/strapi-plugin-upload/admin/src/utils/createFileToDownloadName.js @@ -1,5 +1,9 @@ -const createFileToDownloadName = ({ file: { ext }, fileInfo: { name } }) => { - return `${name.replace(ext, '')}${ext}`; +import { get } from 'lodash'; + +const createFileToDownloadName = ({ file, fileInfo: { name } }) => { + const ext = get(file, 'ext', ''); + + return name.endsWith(ext) ? name : `${name}${ext}`; }; export default createFileToDownloadName;