[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[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&data=01%7C01%7Ceprints-tech%40ecs.soton.ac.uk%7C05c589252219465a030108d8137275c7%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=q8RJB%2FI%2B11HhkybwsSObPIxSeB25nd6Hzy0zkV%2BGOJA%3D&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/e439faba/attachment-0001.html