Skip to content

Fix saving Image Cropper and File Upload editors inside a block#103

Open
talhamalik4025 wants to merge 1 commit into
PerplexDigital:masterfrom
talhamalik4025:fix/block-file-editor-content-key
Open

Fix saving Image Cropper and File Upload editors inside a block#103
talhamalik4025 wants to merge 1 commit into
PerplexDigital:masterfrom
talhamalik4025:fix/block-file-editor-content-key

Conversation

@talhamalik4025

@talhamalik4025 talhamalik4025 commented Jul 24, 2026

Copy link
Copy Markdown

Fixes #102.

If you put an Umbraco Image Cropper or File Upload editor on a block's element type, saving the page fails with "Invalid content key". In ContentBlocksValueEditor.FromEditor the inner ContentPropertyData is created without a ContentKey or PropertyTypeKey, so both default to Guid.Empty. ImageCropperPropertyValueEditor and FileUploadPropertyValueEditor both explicitly throw "Invalid content key" in that case, and need the key to build the media storage path. Editors that only store a reference (e.g. Media Picker v3) ignore the two keys, which is why everything else saves fine.

This sets both keys before calling the inner FromEditor, taking the content key from the incoming editorValue – the same approach Umbraco core takes in BlockValuePropertyValueEditorBase.MapBlockItemDataFromEditor (umbraco/Umbraco-CMS#18976).

Verified on Umbraco 17: with this change the Image Cropper saves correctly inside a block (the file is stored against the content), and reference-based editors like Media Picker are unaffected (Media Picker stores a media-library reference, not a file on the content). File Upload uses the same content-key mechanism as the Image Cropper – the identical "Invalid content key" guard – so it's covered by the same fix.

…ad) inside a block

The inner ContentPropertyData was created without a ContentKey or
PropertyTypeKey, so property editors that store files against the content
key (Image Cropper, MediaPicker3, File Upload) received Guid.Empty and
threw "Invalid content key" on save. Set both keys before calling the
inner FromEditor, mirroring Umbraco core's BlockValuePropertyValueEditorBase.

Fixes PerplexDigital#102
@PerplexDaniel

Copy link
Copy Markdown
Member

Thanks @talhamalik4025 for your detailed issue report and the PR. I'm very busy today but will have a look early next week. The code looks good but I also need to verify it works as intended.

@talhamalik4025 talhamalik4025 changed the title Fix saving file-based editors (image cropper, media picker, file upload) inside a block Fix saving Image Cropper and File Upload editors inside a block Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Cropper (and other file-based editors) can't be saved inside a block – "Invalid content key"

2 participants