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”
Open http://localhost:4502/editor.html/content/myproject1/en.html
Add an image component, set an image, save
Edit that component, press “Clear”, save
Edit that component, set an image, save
Open http://localhost:4502/crx/de/index.jsp#/content/myproject1/en/jcr%3Acontent/root/content/image
fileReference | String[] | /content/dam/myproject1/prague.jpg, /content/dam/myproject1/prague.jpg |
fileReference | String | /content/dam/myproject1/prague.jpg |
I tried the Adobe core component:
http://localhost:4502/crx/de/index.jsp#/apps/myproject1/core/components/content/image
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
cq/gui/components/authoring/dialog/fileupload
wcm-io/wcm/ui/granite/components/form/pathfield
Both Components holds an input field for './fielReference'
cq/gui/components/authoring/dialog/fileupload has a javascript function that deletes duplicated input fields _removeDuplicateHiddenInputs when the component is created
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.
provided a PR: https://github.com/wcm-io/wcm-io-handler/pull/16
fixed in Media Handler 1.9.0 with this PR