You will need to check the saved value for this field.
If you are using permanent URLs for media libraries, the saved URL will be like ~/getmedia/< GUID >. If using direct path - it will be the physical folder path.
If the value is an attachment - the value will be like ~/getattachment/< GUID or path >
And for the CMS.File selection - it will be the node alias path.
So, you need to create a switch statement in which you will check the format of the stored value and then do your logic.