EPrints Technical Mailing List Archive

Message: #03421


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Re: SWORD deposit


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

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.)

  http://eprints.lincoln.ac.uk/sword-app/servicedocument

will return all the formats your repo understands

You will get a list something like:

  <accept alternate="multipart-related">
    application/x-bibtex
  </accept>
  <accept alternate="multipart-related">
    application/x-eprints-import-bibtex; charset=utf-8
  </accept>
  <accept alternate="multipart-related">
    application/x-eprints-import-doi; charset=utf-8
  </accept>
  <accept alternate="multipart-related">
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
  </accept>
  <accept alternate="multipart-related">
    application/vnd.openxmlformats</accept>
  <accept alternate="multipart-related">
    application/msword
  </accept>
  <accept alternate="multipart-related">
    application/x-eprints-import-pubmedid
  </accept>
  <accept alternate="multipart-related">
    application/x-eprints-import-pubmedxml
  </accept>
  <accept alternate="multipart-related">
    application/vnd.rjbroker
  </accept>
  <sword:acceptPackaging>
    http://opendepot.org/broker/1.0
  </sword:acceptPackaging>
  <accept alternate="multipart-related">
    application/vnd.eprints.data+xml; charset=utf-8
  </accept>
  <sword:acceptPackaging>
    http://eprints.org/ep2/data/2.0
  </sword:acceptPackaging>
  <acceptPackaging>
    http://purl.org/net/sword/package/Binary
  </acceptPackaging>
  <accept alternate="multipart-related">
    application/octet-stream
  </accept>

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,
EDINA,
The University of Edinburgh.

http://edina.ac.uk/

This email was sent via the University of Edinburgh.

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