next up previous contents index


30.2.16 Dateien ins Archiv übertragen

Da es im WebDMS möglich ist, eine Datei (PDF- oder Grafikdatei) zum Archivserver zu übertragen, können wir dies auch mit der Fremdansteuerung bewerkstelligen. Im Prinzip verwenden wir dazu den Befehl go_action&action=upload. Allerdings ist es beim Hochladen von Dateien notwendig, bei der Kommunikation mit dem WebDMS in den 'POST'-Modus zu wechseln (dies im Unterschied zum normalerweise verwendeten GET-Modus).

Beim Upload können Sie die Optionen uploadocr=x sowie uploadbits=y mitgeben, um sowohl die OCR-Definition als auch die Rasterung zu bestimmen. Alternativ ist es auch möglich, beim Upload direkt eine Scandefinition zu bestimmen, welche die Verarbeitungsparameter enthält. Dazu verwenden wir uploaddef=x, um eine bestimmte Scandefinition auszuwählen, wobei die erste Scandefinition mit 0 anzusprechen ist.

Anhand des untenstehenden Beispiels zeigen wir den Upload einer Datei zum Web-Server in der Programmiersprache Perl. Anhand der Kommentare sollte es möglich sein, den Upload auch mit einer anderen Programmiersprache hinzukriegen.

#!/usr/bin/perl

# wcupload.pl -> demo script for uploading a document via web client
# (c) 2008 by Archivista GmbH, Urs Pfister

use strict;
use LWP::UserAgent; # we work with UserAgent (our batch web browser)
use HTTP::Cookies; # we need to work with cookies
use HTTP::Request::Common qw(POST); # the post method must be imported

my $fin = "/home/archivista/documentation_de.pdf"; # demo doc (our manual)
my $pages = "1-5"; # pages to extract (so we don't wait too long)
my $fout = "/tmp/eins.pdf"; # the finally file we want to import
if (!-e $fout) { # create file with pdftk if it does not already exist
  system("pdftk $fin cat $pages output $fout");
}

# server we use (link to webclient)
my $server = "http://localhost/perl/avclient/index.pl"; 
# connection string (host,db,user,password)
my $connect = "?host=localhost&db=archivista&uid=Admin&pwd=archivista";

my $www = LWP::UserAgent->new; # new www session 
# save the cookie for the corrent session
$www->cookie_jar(HTTP::Cookies->new('file'=>'/tmp/cookies.lwp','autosave'=>1));
my $res = $www->get("$server$connect"); # connect to webclient 
if ($res->is_success) {
  if ($res->content) { # we got login
    # now upload a file, we use request method with POST
    my $res = $www->request(POST "$server",
      Content_Type => 'form-data', # multipart/form-data
      Content => [ # structure for our file
        MAX_FILE_SIZE => 134217728, # max. size (WebDMS won't accept more)
        upload => [ $fout, $fout ], # file to upload, file name to use 
        go => 'go_action', # we need to call the go_action command
        action => 'upload', # inside of go_action we need to use upload
        uploadbits => 1, # 1=black/white, 8=gray, 24=color
        uploadocr => 27, # the desired ocr def (1-x, 27 does mean: no ocr)
        meta => "Titel:450", # filling in some meta keys is no problem
      ]
    );
    if ($res->is_success) { # if we got a succes, file is uploaded
      print "file $fout uploaded\n";
    }
  }
}

Image tip Hinweis: Das obenstehende Beispiel läuft auf jeder ArchivistaBox. Grundsätzlich kann der WebDMS aber von einem beliebigen Rechner aus angesprochen werden, und selbst das Arbeiten mit verschlüsseltem Zugriff (HTTPS) ist problemlos möglich. Das Programm ist auf der ArchivistaBox-CD unter /home/cvs/archivista/jobs unter dem Namen wcupload.pl zu finden.