[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"

John Salter J.Salter at leeds.ac.uk
Thu Jun 18 11:50:39 BST 2020


HI Patrick,
Thanks for a very well asked question!

I think you just need to do this:
$doc->set_value( "main", $filename );

Cheers,
John

From: eprints-tech-bounces at ecs.soton.ac.uk [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of Patrick Camilleri via Eprints-tech
Sent: 18 June 2020 11:29
To: eprints-tech at ecs.soton.ac.uk
Subject: [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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.researchgate.net%2Fpublication%2F291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software&amp;data=01%7C01%7Ceprints-tech%40ecs.soton.ac.uk%7C7647ee6e6cb6455d0fcd08d8137572d8%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&amp;sdata=XyCIqqbVaTHujDISO2EQ9W36pxUdNexqjICODbhf7Lw%3D&amp;reserved=0<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.researchgate.net%2Fpublication%2F291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software&amp;data=01%7C01%7Ceprints-tech%40ecs.soton.ac.uk%7C7647ee6e6cb6455d0fcd08d8137572d8%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&amp;sdata=XyCIqqbVaTHujDISO2EQ9W36pxUdNexqjICODbhf7Lw%3D&amp;reserved=0>).

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20200618/7e6aee40/attachment-0001.html 


More information about the Eprints-tech mailing list