Changeset 4348 for trunk/tools
- Timestamp:
- Nov 23, 2009, 12:59:14 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/piwigo_remote.pl
r4347 r4348 84 84 85 85 if ($opt{action} eq 'pwg.images.add') { 86 use MIME::Base64 qw(encode_base64);87 86 use Digest::MD5::File qw/file_md5_hex/; 88 87 89 88 $form = {}; 90 $form->{method} = 'pwg.images.add';89 $form->{method} = $opt{action}; 91 90 92 91 my $original_sum = file_md5_hex($opt{original}); … … 115 114 $form->{high_sum} = file_md5_hex($opt{high}); 116 115 } 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 147 if ($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}); 117 180 118 181 foreach my $key (keys %{ $opt{define} }) { … … 334 397 my %params = @_; 335 398 399 use MIME::Base64 qw(encode_base64); 336 400 use File::Slurp; 337 401 … … 376 440 } 377 441 } 442 443 sub 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.