@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
    @PutMapping(value = IMAGE_URL, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public TbResourceInfo updateImage(@Parameter(description = IMAGE_TYPE_PARAM_DESCRIPTION, schema = @Schema(allowableValues = {"tenant", "system"}), required = true)
                                      @PathVariable String type,
                                      @Parameter(description = IMAGE_KEY_PARAM_DESCRIPTION, required = true)
                                      @PathVariable String key,
                                      @RequestPart MultipartFile file) throws Exception {
        TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE);
        resourceValidator.validateResourceSize(getTenantId(), imageInfo.getId(), file.getSize());

        TbResource image = new TbResource(imageInfo);
        image.setData(file.getBytes());
        image.setFileName(file.getOriginalFilename());
        image.updateDescriptor(ImageDescriptor.class, descriptor -> {
            descriptor.setMediaType(file.getContentType());
            return descriptor;
        });
        return tbImageService.save(image, getCurrentUser());
    }
@Test
    public void testUpdateImage() throws Exception {
        String filename = "my_png_image.png";
        TbResourceInfo imageInfo = uploadImage(HttpMethod.POST, "/api/image", filename, "image/png", PNG_IMAGE);
        checkPngImageDescriptor(imageInfo.getDescriptor(ImageDescriptor.class));

        String newFilename = "my_jpeg_image.png";
        TbResourceInfo newImageInfo = uploadImage(HttpMethod.PUT, "/api/images/tenant/" + filename, newFilename, "image/jpeg", JPEG_IMAGE);

        assertThat(newImageInfo.getTitle()).isEqualTo(filename);
        assertThat(newImageInfo.getResourceKey()).isEqualTo(filename);
        assertThat(newImageInfo.getFileName()).isEqualTo(newFilename);
        assertThat(newImageInfo.getPublicResourceKey()).isEqualTo(imageInfo.getPublicResourceKey());

        ImageDescriptor imageDescriptor = newImageInfo.getDescriptor(ImageDescriptor.class);
        checkJpegImageDescriptor(imageDescriptor);

        assertThat(downloadImage("tenant", filename)).containsExactly(JPEG_IMAGE);
        assertThat(downloadImagePreview("tenant", filename)).hasSize((int) imageDescriptor.getPreviewDescriptor().getSize());
    }