Cloudinary
view release on metacpan or search on metacpan
lib/Cloudinary.pm view on Meta::CPAN
Your API key from L<https://cloudinary.com/console>
=head2 api_secret
Your API secret from L<https://cloudinary.com/console>
=head2 private_cdn
Your private CDN url from L<https://cloudinary.com/console>.
=head1 METHODS
=head2 upload
$self->upload(
{
file => $binary_str | $url, # required
format => $str, # optional
public_id => $str, # optional
resource_type => $str, # image or raw. defaults to "image"
tags => ['foo', 'bar'], # optional
timestamp => $epoch, # time()
},
sub { my ($cloudinary, $res) = @_ }
);
Will upload a file to L<http://cloudinary.com> using the parameters given
L</cloud_name>, L</api_key> and L</api_secret>. C<$res> in the callback
will be the json response from cloudinary:
{
url => $str,
secure_url => $str,
public_id => $str,
version => $str,
width => $int, # only for images
height => $int, # only for images
}
C<$res> on error can be either C<undef> if there was an issue
connecting/communicating with cloudinary or a an error data structure:
{error => {message: $str}}
The C<file> can be:
=over 4
=item * A hash
{ file => 'path/to/image' }
=item * A L<Mojo::Upload> object.
=item * A L<Mojo::Asset> object.
=item * A URL
=back
C<res> in callbacks will be the JSON response from L<http://cloudinary.com>
as a hash ref. It may also be C<undef> if something went wrong with the
actual HTTP POST.
See also L<https://cloudinary.com/documentation/upload_images> and
L<http://cloudinary.com/documentation/upload_images#raw_uploads>.
=head2 destroy
$self->destroy(
{
public_id => $public_id,
resource_type => $str, # image or raw. defaults to "image"
},
sub { my ($cloudinary, $res) = @_; }
);
Will delete an image from cloudinary, identified by C<$public_id>.
The callback will be called when the image got deleted or if an error occur.
On error, look for:
{error => {message: $str}}
See also L<https://cloudinary.com/documentation/upload_images#deleting_images>.
=head2 url_for
$url_obj = $self->url_for("$public_id.$format", \%args);
This method will return a public URL to the image at L<http://cloudinary.com>.
It will use L</private_cdn> or the public CDN and L</cloud_name> to construct
the URL. The return value is a L<Mojo::URL> object.
Example C<%args>:
{
h => 150, # height of image
w => 100, # width of image
resource_type => $str, # image or raw. defaults to "image"
secure => $bool, # use private_cdn or public cdn
type => $str, # upload, facebook. defaults to "upload"
}
See also L<http://cloudinary.com/documentation/upload_images#accessing_uploaded_images>
and L<http://cloudinary.com/documentation/image_transformations>.
=head1 COPYRIGHT & LICENSE
This library is free software. You can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 AUTHOR
Jan Henning Thorsen - jhthorsen@cpan.org
=cut
( run in 0.484 second using v1.01-cache-2.11-cpan-39bf76dae61 )