2

We have <setting name="Media.UploadAsFiles" value="true">. In most scenarios it's working as expected; media items' data bits are stored as files on the server rather than in the Sitecore DB.

However, for some media templates, e.g. /sitecore/templates/System/Media/Unversioned/Pdf, the Attach command on the Media field in the Content Editor ignores our UploadAsFiles setting; it apparently stores the media data bits in the Sitecore DB rather than as a file.

Actually, it's not "obvious" that it's storing the bits in the DB, since media items show no explicit "DB/file" indicator AFAICT, but I infer it's using DB storage because the "File Path" field is blank, we can't find the file on the server, yet the media item still "works".

We need to use Detach and Attach to update a media item's bits, and we want the item to still use file storage after we do this.

This is Sitecore XP 8.2 rev. 180406 (Update-7).

Has anyone seen this problem? Know a fix or workaround? Thanks!

2

When you are attaching the pdf/any media stream the below processors are getting executed.

<attachFile argsType="Sitecore.Pipelines.Attach.AttachArgs">
  <processor mode="on" type="Sitecore.Pipelines.Attach.CheckSize,Sitecore.Kernel"/>
  <processor mode="on" type="Sitecore.Pipelines.Attach.UpdatePath,Sitecore.Kernel"/>
  <processor mode="on" type="Sitecore.Pipelines.Attach.Save,Sitecore.Kernel"/>
</attachFile>

UpdatePath processor checks "File Path" field of the media item and if it is empty/null then it attaches the file to the DB instead of File system i guess; regardless of "UploadAsFiles" setting true/false.

If you are using the "Versioned" templates [ex - /sitecore/templates/System/Media/Versioned/Pdf] and Workflow enabled then you may not see this scenario. Because your initial version will be having the "File Path" value and the "File Path" is not a shared field in versioned templates, so when you detach and attach the file in further versions [2/3/etc.] will be saved in file system.

If you are using the "Unversioned" templates [ex - /sitecore/templates/System/Media/Unversioned/Pdf]

(I guess by default this will be used when your "Media.UploadAsVersionableByDefault" setting is false in your config or you don't check the "Make uploaded media items versionable" while uploading the file)

then the initial file upload stores the file in file system but the further detach and attach is getting stored in DB. Because the detach is clearing the "File Path" and it's a shared field in UnVersioned templates, so when attaching the file again is not updating the File Path.

As a workaround i guess we can just attach the file without detaching it. [I don't see any issues attaching the file without detaching it]. But when we create a media item using any template [ex - /sitecore/templates/System/Media/Unversioned/Pdf] instead of upload as a file and try to attach the file in media field then that is not getting saved in DB. [even if "UploadAsFiles" as "True"]

Not sure whether the workaround makes sense for requirement, you can even consider replacing the default attach processors or inject your custom code but I would recommend you to reach out to Sitecore to check whether they have a patch/fix for this.

  • 1
    Thanks for the excellent analysis. The "just don't Detach first" workaround seems to work; I've suggested it to my users. – Conrad Albrecht May 2 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.