There is a case that fileReference is set as an array in the JCR.
This happens when there is an image, which already has an asset set, editing it, clearing the reference and setting a new image.
Setup a new AEM 6.5 author on port 4502
Create a sample project using wcm.io archetype
Using example from "AEM project with wcm.io and Sling-Initial-Content project layout and Java 11"
Install the sample project “./build-deploy.sh”
Add an image component, set an image, save
Edit that component, press “Clear”, save
Edit that component, set an image, save
I tried the Adobe core component:
set sling:resourceSuperType to core/wcm/components/image/v2/image
The problem does not occur
The problem lies in wcm-io/handler/media/components/granite/form/fileupload
where two components are merged together
Both Components holds an input field for './fielReference'
So the composition of both components works most of the time. But, when the component is saved without an image and opened again, cq/gui/components/authoring/dialog/fileupload holds the input field instead of wcm-io/wcm/ui/granite/components/form/pathfield.
This could be because wcm-io/wcm/ui/granite/components/form/pathfield has no './fielReference' input field at this time or the _removeDuplicateHiddenInputs function removes the field in another order.
When an image is then dropped in the component wcm-io/wcm/ui/granite/components/form/pathfield also gets a './fielReference' input field. So the value is posted twice.
fixed in Media Handler 1.9.0 with this PR