<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US">HI Patrick,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US">Thanks for a very well asked question!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US">I think you just need to do this:<br>
$doc-&gt;set_value( &quot;main&quot;, $filename );<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US">Cheers,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US">John<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk]
<b>On Behalf Of </b>Patrick Camilleri via Eprints-tech<br>
<b>Sent:</b> 18 June 2020 11:29<br>
<b>To:</b> eprints-tech@ecs.soton.ac.uk<br>
<b>Subject:</b> [EP-tech] Adding file to eprints record using perl script results in &quot;In PDF Document: You need to select a file to be shown first&quot;<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">Hello,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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 &quot;In PDF document: You
 need to select a file to be shown first&quot;.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">To be more precise this is what I see in the browser:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">- 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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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: &quot;In PDF document: You need to select a file to be shown first&quot;.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Is there I command I'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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">This is the relevant Perl code which I'm using to attach a pdf to an already existing&nbsp;record (inspired from&nbsp;<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%7C7647ee6e6cb6455d0fcd08d8137572d8%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&amp;sdata=XyCIqqbVaTHujDISO2EQ9W36pxUdNexqjICODbhf7Lw%3D&amp;reserved=0" originalSrc="https://www.researchgate.net/publication/291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software" shash="qD6I30amLp/vLy8uSYKOwC7npgqUpYXrVB9kRoRKTvZWkQ+IbQdYP9XEkElJHt5rFcdIC468fEThcYQekFFz/Al6IYoDbIF7u1Ft6BRFwNhV2UbmMS67KpVxjB3XwEaZ8I8Kp4AG3gT3AWwvq7o2tyNy+ywdffgJlQzcCP6n+Bg=">https://www.researchgate.net/publication/291251891_Batch_Ingesting_into_EPrints_Digital_Repository_Software</a>).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">my $dataset_id = 'eprint';<br>
my $repositoryid = 'myrepo';<br>
<br>
# Create session<br>
my $session = EPrints::Session-&gt;new( 1, $repositoryid );<br>
<br>
# Get all eprints in 'eprint'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>
&nbsp; &nbsp;my ( $session, $ds, $eprint ) = @_;<br>
<br>
&nbsp; &nbsp;#create document object, add pdf files to document, attach to eprint object, and move to live archive<br>
&nbsp; &nbsp;my $doc = EPrints::DataObj::Document::create( $session, $eprint );<br>
<br>
&nbsp; &nbsp;# Not showing how $filepath and $filename are generated but debugging the variables shows the following</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp;# $filepath = '/opt/eprints3/import-data/filename.pdf'</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp;# $filename = 'filename.pdf'<br>
&nbsp; &nbsp;$doc-&gt;add_file( $filepath, $filename );<br>
&nbsp; &nbsp;$doc-&gt;set_value( &quot;format&quot;, &quot;application/pdf&quot; );<br>
<br>
&nbsp; &nbsp;# I notice that $eprint-&gt;fileinfo has the directory path to the pdf but the filename is not appeneded to the path<br>
&nbsp; &nbsp;# I hacked the commit sub to append the filename at the end of the filepath but this still resulted in the wrong<br>
&nbsp; &nbsp;# link and the message 'select a file to be shown first'.<br>
&nbsp; &nbsp;$doc-&gt;commit();<br>
<br>
&nbsp; &nbsp;$eprint-&gt;move_to_archive;<br>
}</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Patrick<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>