Blog entry

Drupal 7, IMCE, Media and public and private files

Today I decided to tackle the problem of needing public and private files. Again.

At the first attempt I switched the default download method  in admin/config/media/file-system from 'public' to 'private'. From that moment on, no picture was visible any more. After many hours of digging around, I gave up and switched the download method back to public.

Later I found that all pictures needed to be referenced in the database with a 'public://' or a 'private://' prefix.

With the move from IMCEImage to FileField, this was fixed.

So, after switching to 'private' again today, all publicly available images remained visible. Yey!

Reading up on the Drupal documentation and explanations of others I realised that the default download method set to 'private' is the route to take. Public files remain visible either through a Drupal page or as deeplink to the file (something to fix later on). Private files are not visible through a deeplink, but still visible for authenticated users.

By creating a special document type 'membersonly' with a field of type File for the attachments that is only available for users having a special role, I managed to make my 'members only' part a little more flexible. I set the attachment field to only use private files and lo and behold: I could upload a file as an attachment and it ended up in the designated, private directory. However, I wasn't able to reuse the uploaded file, because there was no way of selecting the file on the server directory.

As said earlier: I do like to have a file browser available, so with the help of FileField Sources and IMCE the field was configured to use both the upload and a file browser.

I had to tweak the FileField Sources code, because it cleared all buttons from the IMCE browser, including the 'insert file' button.

Now I was able to select the file, uploaded by the default upload process of the FileField. Too bad, it wasn't accepted because of missing database information. I'm not sure which information was necessary, because the file was already uploaded through the upload process and therefore there was a record in the database.

Alternative: the Media module.

One the problems I have with the current Drupal 6 configuration is the Gallery2 module which integrates a Gallery2 site within a Drupal page. There is no active development anymore and I'm afraid to update Gallery2 because this integration module might not work anymore.

Looking at the Media Gallery provided in the Drupal Gardens environment, this looks like a promising alternative.

So I installed the Media module. I immediately ran into the problem of missing types in the file_managed records, but once I figured out what the content was supposted to be, that was easily fixed with some MySQL queries.

The Media module provides a basic file browser, but it's based on the records in the file_managed table, so no nice drill down to the relevant directory but a large number of thumbnails of all images available. And nothing from the private section.

So I'm facing to fix the last piece of the puzzle to have proper handling of public and private files and it comes down to figuring out how to either turn the Media browser into a file browser or make FileField accept the choices made in the IMCE browser.