Java Additional topics
Overview
Cloudinary is a cloud-based service that provides an end-to-end image and video management solution including uploads, storage, administration, image manipulation, and delivery.
Cloudinary's Java library wraps Cloudinary's upload API for easily uploading images, videos and raw files to the cloud. In addition, the Java library simplifies the generation of manipulation URLs and includes view helper methods for embedding transformed images and videos in your web views.
This page includes additional details regarding the integration of Cloudinary with your Java applications.
Configuration options
Setting the configuration parameters can be done either programmatically using appropriate constructor of Cloudinary class or globally using an environment variable.
Your Cloud Name account parameter is required to build URLs for your media assets. API Key and API Secret are further needed to perform secure API calls to Cloudinary (e.g., image and video uploads). See Account and API setup for more details.
You can find your configuration parameters in the dashboard of our Management Console.
Here's an example of setting configuration parameters in your Java application:
Map config = ObjectUtils.asMap( "cloud_name", "my_cloud_name", "api_key", "my_api_key", "api_secret", "my_api_secret"); Cloudinary cloudinary = new Cloudinary(config);
Another configuration option allows you to dynamically configure the Cloudinary library by defining the CLOUDINARY_URL environment variable. The configuration URL is available in the Management Console's dashboard of your account. When using Cloudinary through a PaaS add-on (e.g., AppFog), this environment variable is automatically defined in your deployment environment. Here's a sample value:
CLOUDINARY_URL=cloudinary://my_api_key:my_api_secret@my_cloud_name
In addition to the three mandatory configuration parameters mentioned above, you can define various optional configuration parameters either by passing them to the Cloudinary constructor or in each API call using methods of Url class. Optional parameters:
- cdn_subdomain or cdnSubdomain on the Url object - Boolean (default: false). Whether to automatically build URLs with multiple CDN sub-domains. See this blog post for more details.
- private_cdn or privateCdn on the Url object - Boolean (default: false). Should be set to true for Advanced plan's users that have a private CDN distribution.
- secure_distribution or secureDistribution on the Url object - The domain name of the CDN distribution to use for building HTTPS URLs. Relevant only for Advanced plan's users that have a private CDN distribution.
- cname - Custom domain name to use for building HTTP URLs. Relevant only for Advanced plan's users that have a private CDN distribution and a custom CNAME.
- secure - Boolean (default: false). Force HTTPS URLs of resources even if embedded in non-secure HTTP pages.
Admin API
While using Cloudinary, all your images and videos are uploaded to the cloud. You can use our Media Library web interface to browse through your uploaded media assets and generated transformations.
In addition, you can use Cloudinary's administrative API: an intuitive RESTful HTTP API for programmatically managing all of your Cloudinary hosted assets. Main supported operations:
- Listing all uploaded images, videos and raw files.
- Receiving details and metadata for uploaded media assets, including timestamps, format, dimensions, etc.
- Listing the derived versions of uploaded resources.
- Finding all resources that share a given tag.
- Listing all transformations.
- Listing tags.
- Receiving transformation details.
- Creating named transformations.
- Updating an existing transformation.
- Deleting resources, derived resources and transformations.
For example, the following Java command returns the details of an uploaded image according to its public ID:
Map config = ObjectUtils.asMap( "cloud_name", "my_cloud_name", "api_key", "my_api_key", "api_secret", "my_api_secret"); Cloudinary cloudinary = new Cloudinary(config); Map result = cloudinary.api().resource("sample", ObjectUtils.emptyMap());
will result in:
{ "public_id": "sample", "format": "jpg", "version": 1312461204, "resource_type": "image", "type": "upload", "created_at": "2011-08-04T12:33:24Z", "bytes": 120253, "width": 864, "height": 576, "url": "http://res.cloudinary.com/demo/image/upload/v1312461204/sample.jpg", "secure_url": "https://.../image/upload/v1312461204/sample.jpg", "next_cursor": "041a39fc10971b9eabd4993470f6bfaf", "derived": [ { "transformation": "c_fill,w_100,h_100", "format": "jpg", "bytes": 7112, "id": "8267a869b62a93a59248f35d7f124c1f", "url": "http://.../demo/image/upload/c_fill,w_100,h_100/v1312461204/sample.jpg", "secure_url": "https://.../image/upload/c_fill,w_100,h_100/v1312461204/sample.jpg" }, { "transformation": "w_230,h_168,c_fit", "format": "jpg", "bytes": 19173, "id": "383e22a57167445552a3cdc16f0a0c85", "url": "http://.../demo/image/upload/w_230,h_168,c_fit/v1312461204/sample.jpg", "secure_url": "https://.../image/upload/w_230,h_168,c_fit/v1312461204/sample.jpg" } ] }
For a general overview and more examples, see this blog post: RESTful API for managing your website's images and other online assets
For more details, see our complete reference of the Admin API.