6

In Drupal 6, the Private Upload module allows you to specify that a node file attachment should be stored in the private file system, so that it is not directly accessible by URL. There is a checkbox that toggles public/private.

In Drupal 7, some of this functionality has been moved into core. When you create a File field, you specify whether it uploads into the public or private file system. However, you cannot toggle public/private on each upload.

So what would be the best way in Drupal 7 to be able to specify that some file attachments be be in the public file system, and some be private? I could create two kinds of file fields, public and private, and have each node type have both kinds of file fields. Or I could have separate (though probably otherwise identical) public and private node types, with corresponding file fields. Both ways are awkward.

Any modules that would help with this that I have missed? (I put in a core feature request for a public/private toggle in the field, but that won't help in the short term.)

  • How do you determine when a file should be public or private if you were able to achieve one field for both options? – nmc Jul 22 '11 at 15:10
  • @nmc: I'm not sure what you mean by "determine". Do you mean Drupal or the person doing the uploading? In our case, the person doing the uploading knows whether it should be public or private. And Drupal will remember because it stores an internal URL ("public://..." or "private://...") that determines whether the file is public or private. The URL is in the file_managed database table; take a look in your own table for some examples – Dan Halbert Jul 28 '11 at 19:53
  • I was wondering how Drupal would know initially whether the person doing the uploading wanted the file public or private if using the same file field for both options. Missed the part in your question about the toggle which I guess is what you're looking for. – nmc Jul 28 '11 at 20:03
  • (I added a link to the core feature request in the original question.) – Dan Halbert Jul 29 '11 at 18:29
3

What you want is to build a custom widget for the file field type, that has a checkbox that says "this file should be private". Drupal 7 natively handles per-file public/private upload, so at this point it is nothing more then a UI issue.

It has been stated that Private Upload will not be ported to Drupal 7, but I think this is wrong. It should be ported and provide two features:

  • An upgrade path from the custom, hackish, storage of private files in Private Upload to proper private files (this is not going to happen by magic)
  • A custom widget that allows the user to choose between public and private during upload
  • I was hoping not to have to write a module (which I haven't done before), but have been looking into using hook_field_widget_info_alter to tweak the current widget to add a toggle. I do wish the functionality were part of core; it seems like an obvious use case. – Dan Halbert Aug 3 '11 at 9:50
2

With OG, I have created my own switch by using file_field_paths and entering [node:group_content_access]/[node:nid] as the path to store files. In my case every node published should be in an OG. Depending on the visibility of the node published, the files are put into a public or private section.

Note however, that this heavily depends on the contents of the group_content_access or Group Visibility field.

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.