1Upload(3)             User Contributed Perl Documentation            Upload(3)
2
3
4

NAME

6       Flickr::Upload - Upload images to "flickr.com"
7

SYNOPSIS

9               use Flickr::Upload;
10
11               my $ua = Flickr::Upload->new(
12                       {
13                               'key' => '90909354',
14                               'secret' => '37465825'
15                       });
16               $ua->upload(
17                       'photo' => '/tmp/image.jpg',
18                       'auth_token' => $auth_token,
19                       'tags' => 'me myself eye',
20                       'is_public' => 1,
21                       'is_friend' => 1,
22                       'is_family' => 1
23               ) or die "Failed to upload /tmp/image.jpg";
24

DESCRIPTION

26       Upload an image to flickr.com.
27

METHODS

29   new
30               my $ua = Flickr::Upload->new(
31                       {
32                               'key' => '90909354',
33                               'secret' => '37465825'
34                       });
35
36       Instatiates a Flickr::Upload instance. The "key" argument is your API
37       key and the "secret" is the API secret associated with it. To get an
38       API key and secret, go to <http://www.flickr.com/services/api/key.gne>.
39
40       The resulting Flickr::Upload instance is a subclass of Flickr::API and
41       can be used for any other Flickr API calls.  As such, Flickr::Upload is
42       also a subclass of LWP::UserAgent.
43
44   upload
45               my $photoid = $ua->upload(
46                       'photo' => '/tmp/image.jpg',
47                       'auth_token' => $auth_token,
48                       'tags' => 'me myself eye',
49                       'is_public' => 1,
50                       'is_friend' => 1,
51                       'is_family' => 1
52                       'async' => 0,
53               );
54
55       Taking a Flickr::Upload instance $ua as an argument, this is basically
56       a direct interface to the Flickr Photo Upload API. Required parameters
57       are "photo" and "auth_token".  Note that the "auth_token" must have
58       been issued against the API key and secret used to instantiate the
59       uploader.
60
61       Returns the resulting identifier of the uploaded photo on success,
62       "undef" on failure. According to the API documentation, after an upload
63       the user should be directed to the page
64       <http://www.flickr.com/tools/uploader_edit.gne?ids=$photoid>.
65
66       If the "async" option is non-zero, the photo will be uploaded
67       asynchronously and a successful upload returns a ticket identifier. See
68       <http://flickr.com/services/api/upload.async.html>. The caller can then
69       periodically poll for a photo id using the "check_upload" method. Note
70       that photo and ticket identifiers aren't necessarily numeric.
71
72   check_upload
73               my %status2txt = (0 => 'not complete', 1 => 'completed', 2 => 'failed');
74               my @rc = $ua->check_upload( @ticketids );
75               for( @rc ) {
76                       print "Ticket $_->{id} has $status2txt{$_->{complete}}\n";
77                       print "\tPhoto id is $_->{photoid}\n" if exists $_->{photoid};
78               }
79
80       This function will check the status of one or more asynchronous
81       uploads. A list of ticket identifiers are provided (@ticketids) and
82       each is checked. This is basically just a wrapper around the Flickr API
83       "flickr.photos.upload.checkTickets" method.
84
85       On success, a list of hash references is returned. Each hash contains a
86       "id" (the ticket id), "complete" and, if completed, "photoid" members.
87       "invalid" may also be returned.  Status codes (for "complete") are as
88       documented at <http://flickr.com/services/api/upload.async.html> and,
89       actually, the returned fields are identical to those listed in the
90       "ticket" tag of the response.  The returned list isn't guaranteed to be
91       in any particular order.
92
93       This function polls a web server, so avoid calling it too frequently.
94
95   make_upload_request
96               my $req = $uploader->make_upload_request(
97                       'auth_token' => '82374523',
98                       'tags' => 'me myself eye',
99                       'is_public' => 1,
100                       'is_friend' => 1,
101                       'is_family' => 1
102               );
103               $req->header( 'X-Greetz' => 'hi cal' );
104               my $resp = $ua->request( $req );
105
106       Creates an HTTP::Request object loaded with all the flick upload
107       parameters. This will also sign the request, which means you won't be
108       able to mess any further with the upload request parameters.
109
110       Takes all the same parameters as upload, except that the photo argument
111       isn't required. This in intended so that the caller can include it by
112       messing directly with the HTTP content (via $DYNAMIC_FILE_UPLOAD or the
113       HTTP::Message class, among other things). See "t/" directory from the
114       source distribution for examples.
115
116       Returns a standard HTTP::Response POST object. The caller can manually
117       do the upload or just call the upload_request function.
118
119   upload_request
120               my $photoid = upload_request( $ua, $request );
121
122       Taking (at least) LWP::UserAgent and HTTP::Request objects as
123       arguments, this executes the request and processes the result as a
124       flickr upload. It's assumed that the request looks a lot like something
125       created with make_upload_request. Note that the request must be signed
126       according to the Flickr API authentication rules.
127
128       Returns the resulting identifier of the uploaded photo (or ticket for
129       asynchronous uploads) on success, "undef" on failure. According to the
130       API documentation, after an upload the user should be directed to the
131       page <http://www.flickr.com/tools/uploader_edit.gne?ids=$photoid>.
132
133   file_length_in_encoded_chunk
134               $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;
135               my $photo = 'image.jpeg';
136               my $photo_size = (stat($photo))[7];
137               my $req = $ua->make_upload_request( ... );
138               my $gen = $req->content();
139               die unless ref($gen) eq "CODE";
140
141               my $state;
142               my $size;
143
144               $req->content(
145                       sub {
146                               my $chunk = &$gen();
147
148                               $size += Flickr::Upload::file_length_in_encoded_chunk(\$chunk, \$state, $photo_size);
149
150                               warn "$size bytes have now been uploaded";
151
152                               return $chunk;
153                       }
154               );
155
156               $rc = $ua->upload_request( $req );
157
158       This subroutine is tells you how much of a chunk in a series of
159       variable size multipart HTTP chunks contains a single file being
160       uploaded given a reference to the current chunk, a reference to a state
161       variable that lives between calls, and the size of the file being
162       uploaded.
163
164       It can be used used along with HTTP::Request::Common's
165       $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD facility to implement
166       upload progress bars or other upload monitors, see flickr_upload for a
167       practical example and t/progress_request.t for tests.
168

SEE ALSO

170       <http://flickr.com/services/api/>
171
172       Flickr::API
173

AUTHOR

175       Christophe Beauregard, cpb@cpan.org
176
178       This module is not an official Flickr.com (or Ludicorp, or Yahoo)
179       service.
180
181       Copyright (C) 2004,2005 by Christophe Beauregard
182
183       This library is free software; you can redistribute it and/or modify it
184       under the same terms as Perl itself, either Perl version 5.8.3 or, at
185       your option, any later version of Perl 5 you may have available.
186
187
188
189perl v5.12.0                      2008-09-18                         Upload(3)
Impressum