Add a photo.
Because the pwg.images.add method is a bit complex (for reliability reasons), we propose a simpler method to add photos with Piwigo web API.
This method requires authentication with an administrator user.
This method requires an HTTP POST request.
Important note: we are uploading a file, so the HTTP request encoding must be set to “form-data”.
Key | Example | Mandatory? | Description |
---|---|---|---|
image | /path/to/file.jpg | mandatory | the uploaded file. JPG or PNG files only. |
category | 123 | mandatory | the identifier of the destination category, use pwg.categories.getList to find existing categories |
name | A nice title | optional | the title of your photo, don't make it too long (use the comment to go into details |
author | Paul Nikanon | optional | the author of the photo |
comment | A longer description | optional | This description is longer than “name” |
level | 2 | optional | (default = 0) privacy setting. See an example in your Piwigo on screen Administration > Photos > Add. 0 is for everybody, 8 is for admins only |
tags | tag1, tags2, another tag | optional | A list of coma separated tags to describe your photo. Missing tags are created automatically |
This method doesn't expect a “web size” photo. Piwigo will resize the photo if needed and create the thumbnail.
As an administrator, you can set the resize settings on the Administration > Photos > Add > Settings screen.
If the photo is larger than maximum dimensions, then Piwigo will use your photo as a “high definition” photo and resize it for web display.
Here comes a full example in Perl languages:
#!/usr/bin/perl use LWP::UserAgent; my %conf = ( base_url => 'http://piwigo.org/demo', ); my $ua = LWP::UserAgent->new; $ua->cookie_jar({}); $ua->post( $conf{base_url}.'/ws.php', { method => 'pwg.session.login', username => 'john', password => 'NWgeWHjy8', } ); $ua->post( $conf{base_url}.'/ws.php', { method => 'pwg.images.addSimple', image => ['/home/john/photos/wild tiger.jpg'], category => 4, tags => 'tag1, tag2, another tag', name => 'A nice title', comment => 'A longer description', author => 'Paul Nikanon', level => 2, }, 'Content_Type' => 'form-data', );