[librecat-dev] hook for after file is uploaded

Patrick Hochstenbach Patrick.Hochstenbach at UGent.be
Fri May 18 08:37:04 CEST 2018

Hi Jonathan

The place where the binary files of the repostory are stored is an abstraction with interface Catmandu::FileStore. There are different places a file can be stored: in a directory on disk, in a database, on a web service. With the current default settings the files are in a directory location on disk with a path defined in config/files.yml and a directorty structure based on the identifier of the record.

Normally you would never directly access this path, but use Perl code like:

my $file_store = h->get_file_store();
my $files         = $file_store->index->files(123);
my $file           = $files->get(“A_survey_of_stochastic_games_with_limsup_and_liminf_objectives.pdf”);

This $file can be streamed to an IO::Handle like this:

$files->stream($fh, $file);

Or the file can be overwritten from an IO::hande like this:



When you play dirty..you can find out the directory where the files of the publication is stored with the undocumented (special case..never use ..yada yada) method:

my $directory = $file->_path;


I would advice not to change files stored in the repository. You need to update also the publication metadata (e.g. file size , update dates , checksums). Also the file owner maybe not happy never to access anymore the original uploaded document.

What you want to present to the world is an access copy of the original file wth a prepended cover page. This could e.g. be done by overwriting the route ‘/download/:id/:file_id’ (what happens when someone wants to download the file (see: LibreCat::App::Catalogue::file). In your case you many want to create on-the-fly (or cache) a PDF with a cover page.

I think this is a service that might be in general interesting to develop for the LibreCat project: keeping master document as-is but provide a mechanism to provice access copies to the world (hint: you might want to create a git ticket for this feature)


> On 17 May 2018, at 16:36, Jonathan NORRIS <jnorris at ist.ac.at> wrote:
> By 'file_name' do you mean only the file name or the full file path? If so its possible to index the full file path in a layer?
> It seems that when I use 'my $pub = publication->get(123);', I can access the file information with '$pub->{file};':
> [
>   {
>     access_level => "open_access",
>     content_type => "application/pdf",
>     creator => "system",
>     date_created => "2018-05-08T13:52:35Z",
>     date_updated => "2018-05-08T13:52:35Z",
>     file_id => 4348,
>     file_name => "A_survey_of_stochastic_games_with_limsup_and_liminf_objectives.pdf",
>     file_size => 187419,
>     open_access => 1,
>     relation => "main_file",
>   },
> ]
> I could use this along with a Linux find command to find the file from the file_store root.
> Basically I am trying to add a feature for prepending pdf cover pages (generated from html templates) to certain types of publications after the file has been uploaded to the file system. I just need the right hook and the path to the particular files.
>  Thanks,
> Jonathan
> On 05/17/2018 01:48 PM, Patrick Hochstenbach wrote:
>> No,
>> The publication-new hook is executed when a user filling in a new publicaton from scratch. You probably want to look at the publication-update hook …this is when the changes are written back to the disks/databases.
>> The file_name of a particular uploaded file to a record is not indexed by default in the search index (you can do this in a local layer configuration if you want). Or,
>> use a Linux ‘find’ command in the configured filestore.default.options.root directory
>> Patrick
>>> On 17 May 2018, at 13:02, Jonathan NORRIS <jnorris at ist.ac.at> wrote:
>>> Hello,
>>> About the 'publication-new: after-fixes' hook, will this be ran after the the publication file has been uploaded to the file system?
>>> And also, is there a way in librecat to query for the file system location of a publication's file?
>>> Thanks,
>>> Jonathan
>>> IST Austria
>>> _______________________________________________
>>> librecat-dev mailing list
>>> - send list mails to librecat-dev at lists.uni-bielefeld.de
>>> - to unsubscribe or change options, visit https://lists.uni-bielefeld.de/mailman2/cgi/unibi/listinfo/librecat-dev
>>> - project website: http://librecat.org/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20180518/3d1d9997/attachment.asc>

More information about the librecat-dev mailing list