/usr/share/perl5/Flickr/API/Upload.pm is in libflickr-api-perl 1.28-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | package Flickr::API::Upload;
use strict;
use warnings;
use HTTP::Request::Common;
use Net::OAuth;
use URI;
use Carp;
use Digest::MD5 qw(md5_hex);
use Encode qw(encode_utf8);
use parent qw(HTTP::Request);
our $VERSION = '1.28';
sub new {
my ($class, $args) = @_;
my $self;
my @params = (
"title",
"description",
"tags",
"is_public",
"is_friend",
"is_family",
"safety_level",
"content_type",
"hidden"
);
my $photo = {};
unless ( -f $args->{photo}->{photo} && -r $args->{photo}->{photo} ) {
carp "\nPhoto: ",$args->{photo}->{photo},", is not a readable file.\n";
return;
}
#
# make hashref of valid arguments for an upload, ignore extraneous
#
$photo->{photo} = $args->{photo}->{photo};
$photo->{async} = $args->{photo}->{async} || '0';
for my $param (@params) {
if (defined($args->{photo}->{$param})) { $photo->{$param} = $args->{photo}->{$param}; }
}
chomp $photo->{'description'};
delete($args->{photo});
$args->{api}->{request_method} = 'POST'; # required to be POST
if (($args->{api_type} || '') eq 'oauth') {
$args->{api}->{extra_params} = $photo;
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
my $orequest = Net::OAuth->request('protected resource')->new(%{$args->{api}});
$orequest->sign();
my $buzo = $orequest->to_hash();
my @msgarr;
for my $param (sort keys %{$buzo}) {
push(@msgarr,$param);
push(@msgarr,$buzo->{$param});
}
push(@msgarr,'photo');
push(@msgarr, [$photo->{photo}]);
$self = POST $args->{api}->{request_url},
'Content-Type' => 'form-data',
'Content' => \@msgarr;
} # if oauth
else {
my $pixfile = $photo->{photo};
delete $photo->{photo};
$photo->{api_key} = $args->{api}->{api_key};
$photo->{auth_token} = $args->{api}->{token};
my $sig = $args->{api}->{api_secret};
foreach my $key (sort {$a cmp $b} keys %{$photo}) {
my $value = (defined($photo->{$key})) ? $photo->{$key} : "";
$sig .= $key . $value;
}
if ($args->{api}->{unicode}) {
$photo->{api_sig} = md5_hex(encode_utf8($sig));
}
else {
$photo->{api_sig} = md5_hex($sig);
}
my @msgarr;
for my $param (sort keys %{$photo}) {
push(@msgarr,$param);
push(@msgarr,$photo->{$param});
}
push(@msgarr,'photo');
push(@msgarr, [$pixfile]);
$self = POST $args->{api}->{request_url},
'Content-Type' => 'form-data',
'Content' => \@msgarr;
} # else i'm flickr
bless $self, $class;
return $self;
}
sub encode_args {
my ($self) = @_;
my $content;
my $url = URI->new('https:');
if ($self->{unicode}){
for my $k(keys %{$self->{api_args}}){
$self->{api_args}->{$k} = encode_utf8($self->{api_args}->{$k});
}
}
$url->query_form(%{$self->{api_args}});
$content = $url->query;
$self->header('Content-Type' => 'application/x-www-form-urlencoded');
if (defined($content)) {
$self->header('Content-Length' => length($content));
$self->content($content);
}
return;
}
1;
__END__
=head1 NAME
Flickr::API::Upload - An upload via the Flickr API
=head1 SYNOPSIS
=head2 Using the OAuth form:
use Flickr::API;
use Flickr::API::Upload;
my $api = Flickr::API->import_storable_config($config_file);
my $response = Flickr::API->upload({
'photo' => 'path/to/photo,
'async' => 0,
'title' => 'My vacation picture',
'description' => 'Here I am, riding a horse',
});
=head1 DESCRIPTION
This modules does most of the work for the upload method in Flickr::API.
=head1 AUTHOR
Copyright (C) 2016, Louis B. Moore <lbmoore@cpan.org>
=head1 SEE ALSO
L<Flickr::API>.
L<Net::OAuth>,
=cut
|