Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dev:webapi:pwg.images.add [2009/03/25 23:25]
pierrick created
dev:webapi:pwg.images.add [2015/01/07 15:38] (current)
plg typo fixed
Line 9: Line 9:
 ===== pwg.images.addChunk ===== ===== pwg.images.addChunk =====
  
-pwg.images.addChunk adds a chunk in the "upload/buffer" directory. The uploaded chunk filename follows the following format: <original_sum>-<type>-<number>.block+pwg.images.addChunk adds a chunk in the "upload/buffer" directory. The uploaded chunk filename follows the following format: <original_sum>-<type>-<position>.block
  
 ==== Parameters ==== ==== Parameters ====
Line 22: Line 22:
 ===== pwg.images.add ===== ===== pwg.images.add =====
  
-Now that thumbnail, web resized and optionnaly the high resolution chunks have been added, pwg.images.add merge the chunks, copy the produced files into their final directory, register the photo in the database.+Now that thumbnail, web resized and optionnaly the high resolution chunks have been added, pwg.images.add merge the chunks, copy the produced files into their final directory, checks the produced files against their expected md5sums, register the photo in the database.
  
 ==== Parameters ==== ==== Parameters ====
  
-  * //file_sum// : md5sum of the "web resized" photo +  * //original_sum// : md5sum that makes the photo unique
-  * //thumbnail_sum// : md5sum of the thumbnail +
-  * //original_sum// : md5sum that makes the photo unique, most of the time identical to high_sum+
   * //categories// : list of category identifiers where you want the photo to be shown. Optionnaly, you can set a rank inside the  each category. Example : "19,3;16,0;134" will associate the photo to category 19 at rank 3, to category 16 at rank 0 (first position) and to category 134 with an automatic rank (last position).   * //categories// : list of category identifiers where you want the photo to be shown. Optionnaly, you can set a rank inside the  each category. Example : "19,3;16,0;134" will associate the photo to category 19 at rank 3, to category 16 at rank 0 (first position) and to category 134 with an automatic rank (last position).
-  * (optional) //high_sum// : md5sum of the  "high resolution" photo+  * (optional) //original_filename//
   * (optional) //name//   * (optional) //name//
   * (optional) //author//   * (optional) //author//
Line 37: Line 35:
   * (optional) //tag_ids// : list of tag numeric identifiers, separated with commas. Example "23,31,18" will associate the photo to tags 23, 31 and 18.   * (optional) //tag_ids// : list of tag numeric identifiers, separated with commas. Example "23,31,18" will associate the photo to tags 23, 31 and 18.
   * (optional) //level// : 0 (----), 1 (Contacts), 2 (Friends), 4 (Family), 8 (Admins)   * (optional) //level// : 0 (----), 1 (Contacts), 2 (Friends), 4 (Family), 8 (Admins)
 +  * (optional) //check_uniqueness// : check if file already exists (based on filename or md5sum, see $conf['uniqueness_mode'] in include/config_default.inc.php)
 +  * (optional) //image_id// : give an image_id if you want to update an existing photo
 +  * (deprecated) //high_sum//
 +  * (deprecated) //thumbnail_sum//
  
 ===== Examples ===== ===== Examples =====
Line 50: Line 52:
 # #
 # time perl piwigo_remote.pl \ # time perl piwigo_remote.pl \
-#   --action=pwg.images.add \ 
 #   --file=erwann_rocher-web.jpg \ #   --file=erwann_rocher-web.jpg \
-#   --thumb=erwann_rocher-thumb.jpg \ 
-#   --high=erwann_rocher-high.jpg \ 
-#   --original=erwann_rocher-high.jpg \ 
 #   --define categories=9 \ #   --define categories=9 \
 #   --chunk_size=200_000 #   --chunk_size=200_000
Line 70: Line 68:
 GetOptions( GetOptions(
     \%opt,     \%opt,
-    qw/action=s file=s thumbnail=s high=s original=s categories=s chunk_size=i define=s%/+    qw/action=s file=s categories=s chunk_size=i define=s%/
 ); );
  
Line 77: Line 75:
  
 my %conf; my %conf;
-$conf{base_url} = 'http://localhost/piwigo/2.0';+$conf{base_url} = 'http://localhost/piwigo/dev/branches/2.7';
 $conf{response_format} = 'json'; $conf{response_format} = 'json';
 $conf{username} = 'plg'; $conf{username} = 'plg';
Line 100: Line 98:
 ); );
  
-# print ";\n", $ua->cookie_jar->as_string, "\n";;+use MIME::Base64 qw(encode_base64); 
 +use Digest::MD5::File qw/file_md5_hex/; 
 +use File::Slurp;
  
-if ($opt{actioneq 'pwg.images.add') { +$form = {}
-    use MIME::Base64 qw(encode_base64); +$form->{method} = 'pwg.images.add';
-    use Digest::MD5::File qw/file_md5_hex/; +
-    use File::Slurp;+
  
-    $form = {}; +my $original_sum file_md5_hex($opt{file})
-    $form->{method} = 'pwg.images.add';+$form->{original_sum} = $original_sum;
  
-    my $original_sum = file_md5_hex($opt{original}); +send_chunks( 
-    $form->{original_sum= $original_sum;+    filepath => $opt{file}, 
 +    type ='file', 
 +    original_sum =$original_sum
 +);
  
-    send_chunks( +foreach my $key (keys %{ $opt{define} }) { 
-        filepath => $opt{file}, +    $form->{$key} = $opt{define}{$key};
-        type => 'file', +
-        original_sum => $original_sum, +
-    ); +
-    $form->{file_sum} = file_md5_hex($opt{file}); +
- +
-    send_chunks( +
-        filepath => $opt{thumbnail}, +
-        type => 'thumb', +
-        original_sum => $original_sum, +
-    ); +
-    $form->{thumbnail_sum} = file_md5_hex($opt{thumbnail}); +
- +
-    if (defined $opt{high}) { +
-        send_chunks( +
-            filepath => $opt{high}, +
-            type => 'high', +
-            original_sum => $original_sum, +
-        ); +
-        $form->{high_sum} = file_md5_hex($opt{high}); +
-    } +
- +
-    foreach my $key (keys %{ $opt{define} }) { +
-        $form->{$key} = $opt{define}{$key}; +
-    } +
- +
-    my $response = $ua->post( +
-        $conf{base_url}.'/ws.php?format=json', +
-        $form +
-    ); +
- +
-    print "-" x 50, "\n"; +
-    printf("response code    : %u\n", $response->code); +
-    printf("response message : %s\n", $response->message); +
-    print "-" x 50, "\n"; +
-    print "\n"; +
- +
-    if ($response->is_success) { +
-        print "upload successful\n"; +
-    } +
-    else { +
-        warn 'A problem has occured during upload', "\n"; +
-        warn $response->decoded_content, "\n"; +
-        die $response->status_line; +
-    }+
 } }
  
-if ($opt{action} eq 'pwg.categories.add') { +my $response = $ua->post( 
-    $form = { +    $conf{base_url}.'/ws.php?format=json'
-        method ='pwg.categories.add', +    $form 
-        name => $opt{define}{name}, +);
-        parent => $opt{define}{parent}, +
-    };+
  
-    my $response $ua->post( +print "-" x 50, "\n"; 
-        $conf{base_url}.'/ws.php?format=json', +printf("response code    : %u\n", $response->code); 
-        $form +printf("response message : %s\n", $response->message)
-    );+print "-" x 50, "\n"; 
 +print "\n";
  
-    use Data::Dumper+if ($response->;is_success) { 
-    print Dumper(from_json($response->content));+    print "upload successful\n"; 
 +
 +else { 
 +    warn 'A problem has occured during upload', "\n"; 
 +    warn $response->decoded_content, "\n"; 
 +    die $response->status_line;
 } }
  
Line 197: Line 158:
     my %params = @_;     my %params = @_;
  
-    my $content = encode_base64(read_file($params{filepath}));+    use MIME::Base64 qw(encode_base64); 
 +    use File::Slurp; 
 + 
 +    my $content = read_file($params{filepath});
     my $content_length = length($content);     my $content_length = length($content);
     my $nb_chunks = ceil($content_length / $conf{chunk_size});     my $nb_chunks = ceil($content_length / $conf{chunk_size});
Line 215: Line 179:
             {             {
                 method => 'pwg.images.addChunk',                 method => 'pwg.images.addChunk',
-                data => $chunk,+                data => encode_base64($chunk),
                 original_sum => $params{original_sum},                 original_sum => $params{original_sum},
                 position => $chunk_id,                 position => $chunk_id,
 
Back to top
dev/webapi/pwg.images.add.1238023557.txt.gz · Last modified: 2009/03/25 23:25 by pierrick
 
 
github twitter newsletter Donate Piwigo.org © 2002-2022 · Contact