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



Yay! ?
I'm not sure why your other approach didn't work.

Looking at the code, it might have worked if you did it this way:
my $fileobj = $doc->add_file( $filepath, $filename );
$doc->set_main( $fileobj );

The set_main method can (or should be able to) take a filename, or a file-object.

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 12:02
To: John Salter <J.Salter at leeds.ac.uk>; eprints-tech at ecs.soton.ac.uk
Subject: Re: [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"

Hi John,

I can't thank you enough! It worked!

The strange thing is that I had previously tried:
  $doc->set_main($filename);

which I assumed is the same thing as
  $doc->set_value("main", $filename);

but that didn't work.

Thanks again,
Patrick

On Thu, Jun 18, 2020 at 11:50 AM John Salter <J.Salter at leeds.ac.uk<mailto:J.Salter at leeds.ac.uk>> wrote:
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> [mailto: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<mailto: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%7C885a206afd5549f7f41b08d8137b9844%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&amp;sdata=jJFiNOYuIzjBEJmTZYY7gE6%2BZfRxxx%2FDPPUtWR6lqiI%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%7C885a206afd5549f7f41b08d8137b9844%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&amp;sdata=jJFiNOYuIzjBEJmTZYY7gE6%2BZfRxxx%2FDPPUtWR6lqiI%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/db5502f8/attachment-0001.html