[EP-tech] Re: SWORD deposit

Ian Stuart Ian.Stuart at ed.ac.uk
Thu Aug 28 08:57:38 BST 2014

I mis-read the original post..... you're looking for how to POST INTO a 

That's simple.... its an http post request, with certain headers set.

So - the first thing you need to know is how you are going to package 
your deposit (the EPrint XML format is the simplest solution, but 
requires work in your depositing service to create that XML.)


will return all the formats your repo understands

You will get a list something like:

   <accept alternate="multipart-related">
   <accept alternate="multipart-related">
     application/x-eprints-import-bibtex; charset=utf-8
   <accept alternate="multipart-related">
     application/x-eprints-import-doi; charset=utf-8
   <accept alternate="multipart-related">
   <accept alternate="multipart-related">
   <accept alternate="multipart-related">
   <accept alternate="multipart-related">
   <accept alternate="multipart-related">
   <accept alternate="multipart-related">
   <accept alternate="multipart-related">
     application/vnd.eprints.data+xml; charset=utf-8
   <accept alternate="multipart-related">

So the deposit is created (perl-wise) thus:

   my $ep = $session->eprint($eprintid);
   my $mime_type = 'foo'; # where "foo" is one of <accept> values above

   my $ua = LWP::UserAgent->new;
   my $auth = "Basic " . MIME::Base64::encode( "$username:$password", '' );
   my %headers = (
     'X-No-Op'             => 'false',
     'X-Verbose'           => 'true',
     'Content-Disposition' => "filename=" . $some_filename,
     'Content-Type'        => $mime_type,
     'User-Agent'          => 'Your external service',
     'Authorization'       => $auth,

   # This URL is for a new deposit ONLY!
   my $url = 'http://eprints.lincoln.ac.uk/id/contents';

   my $buffer = $scalar_string_of_whats_to_be_deposited;
   my $r = $ua->post( $url, %headers, Content => $buffer );

   my $content = $r->content;
   if ( $r->is_success ) {
     my $return_id;
     print "SUCCESS.\n";
     if ( $content =~ m#<id>([^<]+)</id># ) {
       $return_id = $1 if $1;
     print "return_id = $return_id\n";
   } else {
     print "FAIL\n";

..... Enjoy!

On 27/08/14 18:35, Tommy Ingulfsen wrote:
> Hi Andrew
> David Kane and I wrote a basic PHP library for SWORD deposits:
> https://github.com/davidfkane/eprintsDepositHelper
> I think our use case is quite different to Ian's, and maybe yours too, but
> if you are somewhat familiar with PHP, you may be able to learn a little
> from the spaghetti (the spaghetti is mine, David's code is nicerŠ). You
> can use EPrints' own XML format to deposit, if that fits with what you
> want to do, which EPrints can import automatically.
> The core of EPrints 3.3's SWORD/AtomPub implementation is
> $EPRINTSPATH/perl_lib/EPrints/Apache/CRUD.pm - there is some documentation
> here:
> http://wiki.eprints.org/w/API:EPrints/Apache/CRUD


Ian Stuart.
Developer: ORI, RJ-Broker, and OpenDepot.org
Bibliographics and Multimedia Service Delivery team,
The University of Edinburgh.


This email was sent via the University of Edinburgh.

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

More information about the Eprints-tech mailing list