<div dir="ltr">Hi John,<div><br></div><div>I can't thank you enough! It worked!</div><div><br></div><div>The strange thing is that I had previously tried:</div><div><font face="monospace"> $doc->set_main($filename);</font></div><div><br></div><div>which I assumed is the same thing as</div><div><font face="monospace"> $doc->set_value("main", $filename);</font></div><div><br></div><div>but that didn't work.<br></div><div><br></div><div>Thanks again,</div><div>Patrick</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 18, 2020 at 11:50 AM John Salter <<a href="mailto:J.Salter@leeds.ac.uk">J.Salter@leeds.ac.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-GB">
<div class="gmail-m_5990695789555317034WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">HI Patrick,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Thanks for a very well asked question!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I think you just need to do this:<br>
$doc->set_value( "main", $filename );<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Cheers,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">John<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> <a href="mailto:eprints-tech-bounces@ecs.soton.ac.uk" target="_blank">eprints-tech-bounces@ecs.soton.ac.uk</a> [mailto:<a href="mailto:eprints-tech-bounces@ecs.soton.ac.uk" target="_blank">eprints-tech-bounces@ecs.soton.ac.uk</a>]
<b>On Behalf Of </b>Patrick Camilleri via Eprints-tech<br>
<b>Sent:</b> 18 June 2020 11:29<br>
<b>To:</b> <a href="mailto:eprints-tech@ecs.soton.ac.uk" target="_blank">eprints-tech@ecs.soton.ac.uk</a><br>
<b>Subject:</b> [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"<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hello,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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".<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">To be more precise this is what I see in the browser:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">- 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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">- 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".<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This is the relevant Perl code which I'm using to attach a pdf to an already existing record (inspired from <a href="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%7C538f10bb116944b1291008d81376fc62%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=SCrADpjGrVx2gIEDGHpq%2BQ41U33Yo0ZHrI7bZXHAeKQ%3D&reserved=0" originalSrc="https://www.researchgate.net/publication/291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software" shash="WEq/cnPg8eFXZ/xaDGIjiETxeX3rMlxan5urMkOJz22qQ75g6E8yU3abWMbBbFw81+xVFBzK6cMLBmhi/HSMB+5DeAndznDq33tiYElx9M7DkoodkjF/8WlUmb0iRxJjGb5LrzeFpINc5lO2o7Tfqe0eoQ0DJkY0kMrqR4HoHW4=" target="_blank">https://www.researchgate.net/publication/291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software</a>).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">my $dataset_id = 'eprint';<br>
my $repositoryid = 'myrepo';<br>
<br>
# Create session<br>
my $session = EPrints::Session->new( 1, $repositoryid );<br>
<br>
# Get all eprints in 'eprint'dataset<br>
my $dataset = $session->get_repository->get_dataset($dataset_id);<br>
<br>
# Run attach_file on each eprint object<br>
$dataset->map( $session, \&attach_file );<br>
<br>
# This is just an excerpt of the whole subroutine<br>
sub attach_file {<br>
my ( $session, $ds, $eprint ) = @_;<br>
<br>
#create document object, add pdf files to document, attach to eprint object, and move to live archive<br>
my $doc = EPrints::DataObj::Document::create( $session, $eprint );<br>
<br>
# Not showing how $filepath and $filename are generated but debugging the variables shows the following</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> # $filepath = '/opt/eprints3/import-data/filename.pdf'</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> # $filename = 'filename.pdf'<br>
$doc->add_file( $filepath, $filename );<br>
$doc->set_value( "format", "application/pdf" );<br>
<br>
# I notice that $eprint->fileinfo has the directory path to the pdf but the filename is not appeneded to the path<br>
# I hacked the commit sub to append the filename at the end of the filepath but this still resulted in the wrong<br>
# link and the message 'select a file to be shown first'.<br>
$doc->commit();<br>
<br>
$eprint->move_to_archive;<br>
}</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Please let me know if you require additional information or if I haven't been clear enough in describing the problem.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Regards,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Patrick<u></u><u></u></p>
</div>
</div>
</div>
</div>
</blockquote></div>