[drupal-devel] [feature] Introduce file API hook

killes drupal-devel at drupal.org
Tue Apr 5 16:45:50 UTC 2005

Issue status update for http://drupal.org/node/18934

 Project:      Drupal
 Version:      cvs
 Component:    file system
 Category:     feature requests
 Priority:     normal
 Assigned to:  robertDouglass
 Reported by:  Bèr Kessels
 Updated by:   killes at www.drop.org
 Status:       patch

I also like this patch. It will make the revisioning of files easier.
Currently, I have to keep the nid column in some tables. I can remove
that after the patch has landed and rely on vid only.

killes at www.drop.org

Previous comments:

March 15, 2005 - 17:15 : Bèr Kessels

This simple patch by Robert Douglas introduces a fileapi hook. Nothing
fancy, nothing difficult and most of all harldy any performance
It simply allows modules to hook into the data of the file on:
The reason why this should be here, and not in nodeapi, is because, for
example media.module wants to "do stuff" with the file, like get id3
data and put that into a table on upload of a file.
Another valid use case would be to be able to track and count
downloads. Yet another case would be some file renaming, or organising
in directories.


March 15, 2005 - 18:01 : walkah

+1 for this idea (even though I don't actually see a patch) .
My big concern here is trying to manage the order of operations.
particularly when you get into resizing / re-encoding things. i.e. how
could we handle multiple modules that want to do generate thumbnails?
or multiple bitrates for a media file? 
overall though, i like the idea alot!
(was there actually a patch somewhere?)


March 15, 2005 - 19:00 : Bèr Kessels

Attachment: http://drupal.org/files/issues/upload.module.patch.txt (1.92 KB)

forgot the attachement. *blush*


March 15, 2005 - 19:34 : robertDouglass

how hard would it be to react to these lifecycle events in your
image.module so that any image file that gets uploaded via
upload.module gets handled as an image automatically?
As to the issue of "competing" interests from various modules on the
same events (what you described above), don't we already have that
danger in nodeapi? Have we run into any problems there? The things you
want to do with files are rather discreet, I can't imagine two modules
wanting to read the bitrate of a movie separately. 
Anyway, thanks Bèr for submitting this patch, I'm looking forward to
having people evaluate the idea and help think of possible uses and


March 15, 2005 - 22:12 : javanaut

I would suggest adding a "validate" hook in there as well.  This would
allow for file cleaning modules to be developed (such as virus
scanners).  This could be placed along with the other validation checks
in upload_nodeapi().


March 23, 2005 - 07:44 : robertDouglass

Attachment: http://drupal.org/files/issues/upload.module.patch_0.txt (2.46 KB)

Added validate hook (2 lines). Please verify if this looks like the best
choice of location.


March 23, 2005 - 07:44 : robertDouglass

Changed version to cvs


March 28, 2005 - 23:39 : Amazon

+1 We need this for musicforamerica.  We need to allow artists to enter
meta data about themselves and their files.  Also, we want to be able
to allow for encoding based on the metadata as selected by artists.
So on upload we encode a low bitstream for radio.  We will also encode
at a bitrate the artist allows us to distribute their music.


March 28, 2005 - 23:52 : JonBob

Could we call this hook_file() instead? IIRC, I agree with Dries on this
matter; the similar hook_user() and hook_taxonomy() constructs are more
nicely named than hook_nodeapi() is.


March 29, 2005 - 09:41 : robertDouglass

Attachment: http://drupal.org/files/issues/upload.module.patch_1.txt (2.44 KB)

Sure! It is now hook_file.


March 29, 2005 - 17:54 : joshk

This will be useful for a whole lot of things going forward. Another
example this would help drive is bittorrent integration.


April 5, 2005 - 16:41 : moshe weitzman

i'll add to the chorus that this is a useful, minimally invasive patch.
very drupalish. would be nice to run media.module without needing to
patch core.


April 5, 2005 - 17:41 : chx

another +1
I think, in general, the more hooks, the better. Most time is consumed
by SQL queries and file loading after all, so a few php function calls
are not big deal.

More information about the drupal-devel mailing list