diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index 309bf192bc3..8ba558d7947 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -202,8 +202,6 @@ class ImageManager { } public function updateImage(string $key, string $tmpFile): string { - $this->delete($key); - try { $folder = $this->getRootFolder()->getFolder('images'); } catch (NotFoundException $e) { @@ -217,6 +215,8 @@ class ImageManager { throw new \Exception('Unsupported image type: ' . $detectedMimeType); } + $this->delete($key); + if ($key === 'background') { if ($this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) { try { diff --git a/apps/theming/src/components/admin/FileInputField.vue b/apps/theming/src/components/admin/FileInputField.vue index 581b69570a4..1af133d6991 100644 --- a/apps/theming/src/components/admin/FileInputField.vue +++ b/apps/theming/src/components/admin/FileInputField.vue @@ -76,8 +76,17 @@ async function onChange() { }) mime.value = file.type emit('updated') + } catch (error: any) { + if (error?.response?.status === 422) { + const serverMessage = error.response.data?.data?.message + showError(serverMessage || t('theming', 'Failed to upload image')) + } else { + showError(t('theming', 'Failed to upload image')) + } } finally { isSaving.value = false + // Reset input to allow re-selecting the same file and show validation errors on every attempt + inputElement.value!.value = '' } }