Media API
The Media API provides information about media attribute values.
Using the Media API, you can search for and extract the values for the following attributes:
- Alternative text
- Catalog ID
- Catalog version
- Download URL
- Description
- Media code
- MIME
- URL
The Media API allows users to search for media and to get a media.
Searching
The following section describes the request, request parameters, and response to perform a search using the Media API.
Request
The search request is defined by a GET method followed by the parameters required to execute the search including the query name, parameters, sort parameters, and paging parameters. The following example shows the request format.
GET /media?namedQuery={}¶ms={}&pageSize={}¤tPage={}&sort={}
The following table lists the parameters that you can include in your search.
|
Parameter |
Description |
|---|---|
|
namedQuery |
The namedQuery to be executed. The search was designed to execute predefined queries in the data source. The predefined queries are called namedQueries. Before the application client executes, it needs to know which namedQuery it is to execute SmartEdit provides the namedQueryMediaSearchByCodeCatalogVersion. It searches for all media by code and catalog version. It has the following parameters:
|
|
params |
A dictionary that defines the query parameters to be used in the search. The keys and values are separated by a colon and all subsequent key-value pairs are separated by a comma, for example: code:page,catalogId:electronicsContentCatalog,catalogVersion:Staged. |
|
pageSize |
The number of results to be displayed on each page. |
|
currentPage |
The number of the current page. |
|
sort |
The sort query parameter list that specifies the order in which the search results are to be displayed. It follows the same principle as the parameters, but instead of a Map, this is a collection of ordering criteria. The column name and direction are separated by a colon and the subsequent sorting parameters are separated by a comma, for example: code:ASC,catalogId:electronicsCatalog. |
The following example shows the full URI as a request:
{
"media": [
{
"catalogVersion": "Staged",
"code": "CameraAccessoriesPagePreview",
"catalogId": "electronicsContentCatalog",
"altText": null,
"mime": "image/png",
"downloadUrl": "/medias/CameraAccessoriesPage.png?context=bWFzdGVyfGltYWdlc3w0OTU1NHxpbWFnZS9wbmd8aW1hZ2VzL2hjZC9oMzIvODc5NjI5MjkzOTgwNi5wbmd8MGU4MDJlYTMxODVjNWJiN2RlNTUxOTIxN2Q3MmRiY2YyZmU0N2YwNTM5MGExMTk0MGJmYTZiMmY5YjJkYzgxOQ&attachment=true",
"description": null,
"url": "/medias/CameraAccessoriesPage.png?context=bWFzdGVyfGltYWdlc3w0OTU1NHxpbWFnZS9wbmd8aW1hZ2VzL2hjZC9oMzIvODc5NjI5MjkzOTgwNi5wbmd8MGU4MDJlYTMxODVjNWJiN2RlNTUxOTIxN2Q3MmRiY2YyZmU0N2YwNTM5MGExMTk0MGJmYTZiMmY5YjJkYzgxOQ"
}
]
}
Response
The following example shows the response to the request to the Media Search service:
{
"media": [
{
"catalogVersion": "Staged",
"code": "CameraAccessoriesPagePreview",
"catalogId": "electronicsContentCatalog",
"altText": null,
"mime": "image/png",
"downloadUrl": "/medias/CameraAccessoriesPage.png?context=bWFzdGVyfGltYWdlc3w0OTU1NHxpbWFnZS9wbmd8aW1hZ2VzL2hjZC9oMzIvODc5NjI5MjkzOTgwNi5wbmd8MGU4MDJlYTMxODVjNWJiN2RlNTUxOTIxN2Q3MmRiY2YyZmU0N2YwNTM5MGExMTk0MGJmYTZiMmY5YjJkYzgxOQ&attachment=true",
"description": null,
"url": "/medias/CameraAccessoriesPage.png?context=bWFzdGVyfGltYWdlc3w0OTU1NHxpbWFnZS9wbmd8aW1hZ2VzL2hjZC9oMzIvODc5NjI5MjkzOTgwNi5wbmd8MGU4MDJlYTMxODVjNWJiN2RlNTUxOTIxN2Q3MmRiY2YyZmU0N2YwNTM5MGExMTk0MGJmYTZiMmY5YjJkYzgxOQ"
}
]
}
Get Media by UUID
The following section describes the request and response to get a media based on its UUID.
Request
The following is an example of a request to get a media based on its UUID:
GET /media/{uuid}
Response
The following example shows the response to get the media based on its UUID:
{
"altText" : "Save Big On Select SLR & DSLR Cameras",
"catalogId" : "electronicsContentCatalog",
"catalogVersion" : "Staged",
"code" : "defaultElec_960x330_HomeSpeed_EN_01_960W.jpg",
"downloadUrl" : "/medias/defaultElec-960x330-HomeSpeed-EN-01-960W.jpg?context=bWFzdGVyfGltYWdlc3w2NjQzN3xpbWFnZS9qcGVnfGltYWdlcy9oYTMvaDBhLzg3OTcwOTI2NDI4NDYuanBnfGZkOTBmZGRiYzk1MzllMDc4ODQ1ZjRkN2I5ZWQ3OTg3YWRmMGYzM2QxODI5OTU2ZjU1Nzg1OWE5NzJjYTEwMWI&attachment=true",
"mime" : "image/jpeg",
"url" : "/medias/defaultElec-960x330-HomeSpeed-EN-01-960W.jpg?context=bWFzdGVyfGltYWdlc3w2NjQzN3xpbWFnZS9qcGVnfGltYWdlcy9oYTMvaDBhLzg3OTcwOTI2NDI4NDYuanBnfGZkOTBmZGRiYzk1MzllMDc4ODQ1ZjRkN2I5ZWQ3OTg3YWRmMGYzM2QxODI5OTU2ZjU1Nzg1OWE5NzJjYTEwMWI",
"uuid" : "eyJpdGVtSWQiOiJkZWZhdWx0RWxlY185NjB4MzMwX0hvbWVTcGVlZF9FTl8wMV85NjBXLmpwZyIsImNhdGFsb2dJZCI6ImVsZWN0cm9uaWNzQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6IlN0YWdlZCJ9"
}
Get Media by UUIDs
The following section describes the request and response to get a collection of media based on their UUIDs.
Request
The following is an example of a request to get a collection of media based on their UUIDs. Since a UUID is represented as a long hash string, if you provide many UUIDs as parameters to a GET request, the request could be truncated. Therefore, a POST operation is used instead and the UUIDs are passed as the request body.
POST /media/uuids Headers ------- ContentType: application/json Request body ---------------- uuids: [ mediaUUid1, mediaUUID2, mediaUUID3, ... ]
Response
The following example shows the response to get the media based on its UUID:
{
"media": [
{
"altText" : "Save Big On Select SLR & DSLR Cameras",
"catalogId" : "electronicsContentCatalog",
"catalogVersion" : "Staged",
"code" : "defaultElec_960x330_HomeSpeed_EN_01_960W.jpg",
"downloadUrl" : "/medias/defaultElec-960x330-HomeSpeed-EN-01-960W.jpg?context=bWFzdGVyfGltYWdlc3w2NjQzN3xpbWFnZS9qcGVnfGltYWdlcy9oYTMvaDBhLzg3OTcwOTI2NDI4NDYuanBnfGZkOTBmZGRiYzk1MzllMDc4ODQ1ZjRkN2I5ZWQ3OTg3YWRmMGYzM2QxODI5OTU2ZjU1Nzg1OWE5NzJjYTEwMWI&attachment=true",
"mime" : "image/jpeg",
"url" : "/medias/defaultElec-960x330-HomeSpeed-EN-01-960W.jpg?context=bWFzdGVyfGltYWdlc3w2NjQzN3xpbWFnZS9qcGVnfGltYWdlcy9oYTMvaDBhLzg3OTcwOTI2NDI4NDYuanBnfGZkOTBmZGRiYzk1MzllMDc4ODQ1ZjRkN2I5ZWQ3OTg3YWRmMGYzM2QxODI5OTU2ZjU1Nzg1OWE5NzJjYTEwMWI",
"uuid" : "eyJpdGVtSWQiOiJkZWZhdWx0RWxlY185NjB4MzMwX0hvbWVTcGVlZF9FTl8wMV85NjBXLmpwZyIsImNhdGFsb2dJZCI6ImVsZWN0cm9uaWNzQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6IlN0YWdlZCJ9"
},
{
"altText": "hybris Accelerator",
"catalogId": "electronicsContentCatalog",
"catalogVersion": "Staged",
"code": "/images/theme/logo_hybris_responsive.svg",
"downloadUrl": "/medias/logo-hybris-responsive.svg?context=bWFzdGVyfGltYWdlc3w1Mzc5fGltYWdlL3N2Zyt4bWx8aW1hZ2VzL2g1ZS9oNzQvODc5Njk0OTQ0NjY4Ni5zdmd8OTgzOGM1MzE5Njk4YTI5MzU2NzEzNTk4OTJkYjJlM2U5OGNjZThmYTQ0Y2Y5YmVlMGQ5ZDU2ZDgxMGFmZmEwZA&attachment=true",
"mime": "image/svg+xml",
"url": "/medias/logo-hybris-responsive.svg?context=bWFzdGVyfGltYWdlc3w1Mzc5fGltYWdlL3N2Zyt4bWx8aW1hZ2VzL2g1ZS9oNzQvODc5Njk0OTQ0NjY4Ni5zdmd8OTgzOGM1MzE5Njk4YTI5MzU2NzEzNTk4OTJkYjJlM2U5OGNjZThmYTQ0Y2Y5YmVlMGQ5ZDU2ZDgxMGFmZmEwZA",
"uuid": "eyJpdGVtSWQiOiIvaW1hZ2VzL3RoZW1lL2xvZ29faHlicmlzX3Jlc3BvbnNpdmUuc3ZnIiwiY2F0YWxvZ0lkIjoiZWxlY3Ryb25pY3NDb250ZW50Q2F0YWxvZyIsImNhdGFsb2dWZXJzaW9uIjoiU3RhZ2VkIn0="
}]
}
Get Media by Code
The following sections describe the request and response to get a media based on its code.
Request
The following is an example of a request to get a media based on its code:
GET /catalogs/{catalogId}/versions/{catalogVersion}/media/{code}
The following table lists the parameters that are mandatory to get the media.
|
Parameter |
Description |
|---|---|
| catalogId | The identifier of the catalog. |
| catalogVersion | The catalog version. |
| code | The media code to be returned. |
Response
The following example shows the response to get the media based on its code:
{
"catalogVersion": "Staged",
"code": "CameraAccessoriesPagePreview",
"catalogId": "electronicsContentCatalog",
"altText": null,
"mime": "image/png",
"downloadUrl": "/medias/CameraAccessoriesPage.png?context=bWFzdGVyfGltYWdlc3w0OTU1NHxpbWFnZS9wbmd8aW1hZ2VzL2hjZC9oMzIvODc5NjI5MjkzOTgwNi5wbmd8MGU4MDJlYTMxODVjNWJiN2RlNTUxOTIxN2Q3MmRiY2YyZmU0N2YwNTM5MGExMTk0MGJmYTZiMmY5YjJkYzgxOQ&attachment=true",
"description": null,
"url": "/medias/CameraAccessoriesPage.png?context=bWFzdGVyfGltYWdlc3w0OTU1NHxpbWFnZS9wbmd8aW1hZ2VzL2hjZC9oMzIvODc5NjI5MjkzOTgwNi5wbmd8MGU4MDJlYTMxODVjNWJiN2RlNTUxOTIxN2Q3MmRiY2YyZmU0N2YwNTM5MGExMTk0MGJmYTZiMmY5YjJkYzgxOQ
}
Create Media Using Multipart/Form-Data
The following sections describe the request and response to create new media by uploading a file with form parameters using the multipart/form-data content-type.
Request
The following is an example of a request to create new media:
POST /catalogs/{catalogId}/versions/{catalogVersion}/media
Headers
-------
ContentType: multipart/form-data
Form-Data Params
----------------
code: my-media-code
altText: text to show when image is missing
description: text describing the media
file: my-media.png
Response
The following example shows the response to get after posting the request above for the staged electronics catalog:
{
"code": "my-media-code",
"catalogId": "electronicsContentCatalog",
"catalogVersion": "Staged",
"altText": "text to show when image is missing",
"mime": "image/png",
"downloadUrl": "/medias/my-media.png?context=bWFzd...&attachment=true",
"description": "text describing the media",
"url": "/medias/my-media.png?context=bWFzd...
}
Properties
To permit multipart requests, a multipartResolver was added to the web application context as shown in the following code excerpt:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="${cmswebservices.multipartresolver.upload.maxsize}" />
<property name="maxInMemorySize" value="${cmswebservices.multipartresolver.memory.maxsize}" />
</bean>
The following code excerpt shows the default properties defined for this resolver:
# Max upload size (in bytes) # Default: 20MB cmswebservices.multipartresolver.upload.maxsize=20971520 # Max size of file in memory (in bytes) # Default: 1MB cmswebservices.multipartresolver.memory.maxsize=1048576
Media Format, Media Folder, and Media Container
Media are created by default in the images MdeiaFolder. They do not have any MediaFormat or MediaContainer defined by default.
Facade
The Media API exposes the following facade to search for get media values as shown in the MediaFacade.
public interface MediaFacade
{
MediaData getMediaByCode(String code) throws MediaNotFoundException;
MediaData getMediaByUUID(String uuid) throws MediaNotFoundException;
List<MediaData> getMediaByNamedQuery(NamedQueryData namedQuery);
MediaData addMedia(MediaData media, MediaFileDto mediaFile) throws ValidationException, ConversionException;
}
Beans
The Media API also relies on the following MediaFile DTO declared in the cmsfacades-beans.xml file.
Spring Configuration
The Media its Spring beans in the cmsfacades-spring.xml file and its validation beans in the cmsfacades-validator-spring.xml file.
Spring Beans that Support Searching Media Information
The Media API declares the Spring beans that support the Searching component information functionality in the cmsfacades-spring.xml file.
NamedQuery Service
The NamedQueryService provides the functionality to search for any model using a namedQuery strategy. Internally, the MediaFacade coordinates the search with the NamedQueryService, which exposes the following interface:
public interface NamedQueryService
{
<T> List<T> search(NamedQuery namedQuery) throws InvalidNamedQueryException, SearchExecutionNamedQueryException;
<T> SearchResult<T> getSearchResult(NamedQuery namedQuery) throws InvalidNamedQueryException, SearchExecutionNamedQueryException;
}
The default implementation of the namedQueryService acts as an adapter to the FlexibleSearchService, but it could be changed to use Solr. Also, the default implementation of the NamedQueryFactory uses a simple Map<String, String> that maps the query name to the query to be executed.
Spring Beans that Support the Named Query Service
The Media API declares the Spring beans that support the Named Query Service in the cmsfacades-spring.xml and the cms2-named-queries-spring.xml files.
NamedQuery Validation
The NamedQueryDataValidator validates the NamedQueryData parameter, which is used to perform searches. The Media API defines the bean configuration for the NamedQueryDataValidator and the NamedQueryExistsPredicate in the cmsfacades-validator-spring.xml file.