Ignore:
Timestamp:
Nov 23, 2009, 12:59:14 AM (14 years ago)
Author:
plg
Message:

merge r4345 from branch 2.0 to trunk

feature 1051: ability to add/update a file for an existing photo. For example,
you can add the "high" later. Another example is to update the "web resized"
file (new dimensions is a common example). It also works for thumbnails.
Updating an existing file has no impact on the logical level (list of tags,
list of categories, title, description and so on).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/piwigo_remote.pl

    r4347 r4348  
    8484
    8585if ($opt{action} eq 'pwg.images.add') {
    86     use MIME::Base64 qw(encode_base64);
    8786    use Digest::MD5::File qw/file_md5_hex/;
    8887
    8988    $form = {};
    90     $form->{method} = 'pwg.images.add';
     89    $form->{method} = $opt{action};
    9190
    9291    my $original_sum = file_md5_hex($opt{original});
     
    115114        $form->{high_sum} = file_md5_hex($opt{high});
    116115    }
     116
     117    foreach my $key (keys %{ $opt{define} }) {
     118        $form->{$key} = $opt{define}{$key};
     119    }
     120
     121    my $response = $ua->post(
     122        $conf{base_url}.'/ws.php?format=json',
     123        $form
     124    );
     125
     126    print "-" x 50, "\n";
     127    printf("response code    : %u\n", $response->code);
     128    printf("response message : %s\n", $response->message);
     129    print "-" x 50, "\n";
     130    print "\n";
     131
     132#     use Data::Dumper;
     133#     print Dumper($response->content);
     134#     print Dumper(from_json($response->content));
     135
     136    if ($response->is_success) {
     137        print "upload successful\n";
     138    }
     139    else {
     140        print Dumper($response);
     141        warn 'A problem has occured during upload', "\n";
     142        warn $response->decoded_content, "\n";
     143        die $response->status_line;
     144    }
     145}
     146
     147if ($opt{action} eq 'pwg.images.addFile') {
     148    use Digest::MD5::File qw/file_md5_hex/;
     149
     150    if (not defined $opt{define}{image_id}) {
     151        die '--define image_id=1234 is missing';
     152    }
     153
     154    # which file type are we going to add/update?
     155    my $type = undef;
     156
     157    foreach my $test_type (qw/thumbnail file high/) {
     158        if (defined $opt{$test_type}) {
     159            $type = $test_type;
     160            last;
     161        }
     162    }
     163
     164    if (not defined $type) {
     165        die 'at least one of file/thumbnail/high parameters must be set';
     166    }
     167
     168    my $type_code = typecode_from_typename($type);
     169
     170    send_chunks(
     171        filepath => $opt{$type},
     172        type => $type_code,
     173        original_sum => file_md5_hex($opt{original}),
     174    );
     175
     176    $form = {};
     177    $form->{method} = $opt{action};
     178    $form->{type}   = $type_code;
     179    $form->{sum}    = file_md5_hex($opt{$type});
    117180
    118181    foreach my $key (keys %{ $opt{define} }) {
     
    334397    my %params = @_;
    335398
     399    use MIME::Base64 qw(encode_base64);
    336400    use File::Slurp;
    337401
     
    376440    }
    377441}
     442
     443sub typecode_from_typename {
     444    my ($typename) = @_;
     445
     446    my $typecode = $typename;
     447
     448    if ('thumbnail' eq $typename) {
     449        $typecode = 'thumb';
     450    }
     451
     452    return $typecode;
     453}
Note: See TracChangeset for help on using the changeset viewer.