EPrints Technical Mailing List Archive

Message: #08205


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Adding file to eprints record using perl script results in "In PDF Document: You need to select a file to be shown first"


Hello,

I'm trying to attach a pdf to an already existing record using a perl script but not being fully successful. I'm able to attach the pdf to the record because I can see it in the uploaded items but I get the warning "In PDF document: You need to select a file to be shown first".

To be more precise this is what I see in the browser:

- Under the Preview tab of the record in question, clicking on the PDF icon leads to "404 File not found. Could not find the file: /id/eprint/70/1/". As you can see the filename is missing from the path. The file is in the folder though as I can confirm by browsing to the relevant folder in the terminal.

- Under the Details tab of the record in question, clicking on the PDF icon takes you to the pdf and the link is correct. The message I see on this page is: "In PDF document: You need to select a file to be shown first".

Is there I command I'm missing to execute in addition to $doc->add_file, $doc->set_value and $doc->commit()? See below for a code excerpt.

This is the relevant Perl code which I'm using to attach a pdf to an already existing record (inspired from https://www.researchgate.net/publication/291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software).

my $dataset_id = 'eprint';
my $repositoryid = 'myrepo';

# Create session
my $session = EPrints::Session->new( 1, $repositoryid );

# Get all eprints in 'eprint'dataset
my $dataset = $session->get_repository->get_dataset($dataset_id);

# Run attach_file on each eprint object
$dataset->map( $session, \&attach_file );

# This is just an excerpt of the whole subroutine
sub attach_file {
   my ( $session, $ds, $eprint ) = @_;

   #create document object, add pdf files to document, attach to eprint object, and move to live archive
   my $doc = EPrints::DataObj::Document::create( $session, $eprint );

   # Not showing how $filepath and $filename are generated but debugging the variables shows the following
   # $filepath = '/opt/eprints3/import-data/filename.pdf'
   # $filename = 'filename.pdf'
   $doc->add_file( $filepath, $filename );
   $doc->set_value( "format", "application/pdf" );

   # I notice that $eprint->fileinfo has the directory path to the pdf but the filename is not appeneded to the path
   # I hacked the commit sub to append the filename at the end of the filepath but this still resulted in the wrong
   # link and the message 'select a file to be shown first'.
   $doc->commit();

   $eprint->move_to_archive;
}


Any pointers to what I'm doing wrong is greatly appreciated! Would really love to get this resolved because I have a big library of pdfs which I would like to import.

Please let me know if you require additional information or if I haven't been clear enough in describing the problem.

Regards,
Patrick