Examining the Upload File Insert Option in the Sitecore Media Library

I was looking to make a couple customizations to the media library and realized I had never looked into where the Upload File insert option comes from and how it works.

upload_file

The Upload File “template” is held under the Branches section at: /sitecore/templates/Branches/System/Media.

upload_file_template

You will notice that this section also holds the Upload Files – Advanced insert option. So if you wanted, it’s pretty easy to add the advanced file upload insert option to the Media folder standard values.

upload_advanced

How to add insert options to media items

This may seem a bit odd at first glance but imagine that you wanted the ability to upload files under an existing media item. For example, you may want to upload a thumbnail image directly under a PDF file. The PDF file could then understand that any child image would be displayed as a thumbnail image for that file. That’s just a hypothetical scenario… I’m sure you could think of something more useful.

upload_child_media

Unfortunately the file will not be uploaded to the location that you would expect. If we tried to upload a thumbnail image directly below a PDF file, the image would actually be added as a sibling of the PDF instead of a child. Put another way, the image is added beside the PDF on the same level instead of being added directly below our PDF. WTF!

In order to get this to work as expected, we need to navigate to the Upload File insert option and change some parameters in the command field.

upload_file_command

The tofolder=1 parameter is tricky because it actually directs the media item to be uploaded only as a child of a folder. So that means that instead of our image being uploaded directly below our PDF, it instead looks upward and the image is placed below the parent folder. Thankfully this functionality can be turned off by setting the paramater as tofolder=0 and our image can now uploaded as a child of the PDF as expected!

image_upload_success

Once again, structuring media items in a hierarchy like this is sort of a strange concept in Sitecore but I think it can be a useful way to link media items together. I ended up using this sort of concept in the Sitecore Retina Images module I recently posted about.

Advertisements
Posted in Customization, Sitecore

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s