<div dir="ltr">Hello,<br><div><br></div><div>I&#39;m trying to attach a pdf to an already existing record using a perl script but not being fully successful. I&#39;m able to attach the pdf to the record because I can see it in the uploaded items but I get the warning &quot;In PDF document: You need to select a file to be shown first&quot;.</div><div><br></div><div>To be more precise this is what I see in the browser:</div><div><br></div><div>- Under the Preview tab of the record in question, clicking on the PDF icon leads to &quot;404 File not found. Could not find the file: /id/eprint/70/1/&quot;. 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.</div><div><br></div><div>- 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: &quot;In PDF document: You need to select a file to be shown first&quot;.</div><div><br></div><div>Is there I command I&#39;m missing to execute in addition to $doc-&gt;add_file, $doc-&gt;set_value and $doc-&gt;commit()? See below for a code excerpt.</div><div><br></div><div>This is the relevant Perl code which I&#39;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&amp;data=01%7C01%7Ceprints-tech%40ecs.soton.ac.uk%7C05c589252219465a030108d8137275c7%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&amp;sdata=q8RJB%2FI%2B11HhkybwsSObPIxSeB25nd6Hzy0zkV%2BGOJA%3D&amp;reserved=0" originalSrc="https://www.researchgate.net/publication/291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software" shash="jcDvzpizvDfTteAyInkKH7GSoRAdRC0YZz2ku4B0BhWzwlEXEl7/ra/W5otWTiwfP3oz6NSGu6D3bPbfv99qYmCNfv2OW4cpI6rtBTW97UALP0Cc5J8yUW5KzU/aNcouqzmE582x/LNXNEp74Zk1UORqu1Zxwvm5+QDnL5j3lAo=">https://www.researchgate.net/publication/291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software</a>).</div><div><br></div><div><font face="monospace">my $dataset_id = &#39;eprint&#39;;<br>my $repositoryid = &#39;myrepo&#39;;<br><br># Create session<br>my $session = EPrints::Session-&gt;new( 1, $repositoryid );<br><br># Get all eprints in &#39;eprint&#39;dataset<br>my $dataset = $session-&gt;get_repository-&gt;get_dataset($dataset_id);<br><br># Run attach_file on each eprint object<br>$dataset-&gt;map( $session, \&amp;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</font></div><div><font face="monospace">   # $filepath = &#39;/opt/eprints3/import-data/filename.pdf&#39;</font></div><div><font face="monospace">   # $filename = &#39;filename.pdf&#39;<br>   $doc-&gt;add_file( $filepath, $filename );<br>   $doc-&gt;set_value( &quot;format&quot;, &quot;application/pdf&quot; );<br>        <br>   # I notice that $eprint-&gt;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 &#39;select a file to be shown first&#39;.<br>   $doc-&gt;commit();<br><br>   $eprint-&gt;move_to_archive;<br>}</font><br></div><div><br></div><div>Any pointers to what I&#39;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.</div><div><br></div><div>Please let me know if you require additional information or if I haven&#39;t been clear enough in describing the problem.</div><div><br></div><div>Regards,</div><div>Patrick</div></div>