I would like to know if it is possible to set the directory from which the Media module populates its Library tab in the Media Browser.

For instance, when the newest version of the Media module is installed, the directory its Library tab is populated from seems to be /sites/default/files/field/image/. If another directory is already created on a server which contains a set of images I would like to choose from, is it possible to modify the Media module to look in that directory?

I've spent a fair amount of time digging through the module code and haven't found where the directory default is being set. Has anyone ever attempted this?

  • 1
    I'm not sure whether this helps you, but I found this answer in an older Drupal Answers question about the Media module: drupal.stackexchange.com/a/23207/9379 where it says that Media comes with a standard view (that defines which files are taken into account) Aug 28, 2014 at 20:26
  • I don't think it works like that. For instance, if you have a file field attached to an entity and you specify the folder in which it must store the file then that is taken into account as well. I would think that Media just uses the file's internal path as set by file_entity to load media. Drupal file system will convert it to the correct physical path. I also think that you might have access to the internal and physical paths in the view that the media browser runs on. Aug 29, 2014 at 5:06

1 Answer 1


The Media Browser does not work with a physical path, but with the file managed table, and Drupal file system uses the uri of the file to get to the actual file.

Go to the views settings page admin/structure/views/settings and turn on 'Show the SQL query'.

Then open up the media browser and look at the SQL query. It starts of with

SELECT file_managed.timestamp AS file_managed_timestamp, file_managed.fid AS fid, SUM(file_usage.count) AS file_usage_count
{file_managed} file_managed

which means it is using the file_managed table as its base. That comes from the file module in Core. Looking at that table definition in PHPMyAdmin for instance will reveal a fid as the primary identifier, a filename, a uri, filemime and some other fields. The uri is the important part as it tells Drupal how to get to files. The uri is prefixed by the stream wrapper (PHP classes that provide a common interface for getting to resources) and the two common Drupal ones are public:// and private://.

The media module already provides a remote internet sources wrapper, and Remote stream wrapper module provides a Remote Url plugin for the media module.

You can also write your own. Writing stream wrappers

  • This comment is a thank you @J.Reynolds, but also a quick explanation of how your answer helped me. After inspecting the file_managed table I decided to try and insert another row and use the uri field to link to an image I placed in a folder on my local server. I then added a file path filter to the Media Browser block that started with the directory (public://images) and the image appeared. So the record in the file_managed table was the missing link. Aug 29, 2014 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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