To list content renditions for a file use the RenditionsApi.listRenditions method.
For more information about this ReST API endpoint, see List File Renditions.
For a description of the common parameters, such as where, see Common Parameters.
import org.alfresco.core.handler.RenditionsApi;
import org.alfresco.core.model.RenditionEntry;
import org.alfresco.core.model.RenditionPagingList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;
@Component
public class ListRenditionsCmd {
static final Logger LOGGER = LoggerFactory.getLogger(ListRenditionsCmd.class);
@Autowired
RenditionsApi renditionsApi;
public void execute(String fileNodeId) throws IOException {
RenditionPagingList nodeRenditions = listRenditions(fileNodeId);
}
/**
* List renditions for a file node.
*
* @param fileNodeId the id of the file node
* @return a list of renditions, or null if not found
*/
private RenditionPagingList listRenditions(String fileNodeId) {
String where = null; // filter renditions
LOGGER.info("Listing versions for file node ID {}", fileNodeId);
RenditionPagingList result = renditionsApi.listRenditions(fileNodeId, where).getBody().getList();
for (RenditionEntry renditionEntry: result.getEntries()) {
LOGGER.info("Node rendition: " + renditionEntry.getEntry().toString());
}
return result;
}
}
Executing this code looks like this, here we are listing renditions for a text file:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar list-renditions 0492460b-6269-4ca1-9668-0d934d2f3370
2021-04-29 13:58:25.387 INFO 19701 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.131 seconds (JVM running for 3.822)
2021-04-29 13:58:25.389 INFO 19701 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: list-renditions
2021-04-29 13:58:25.390 INFO 19701 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[1]: 0492460b-6269-4ca1-9668-0d934d2f3370
2021-04-29 13:58:25.391 INFO 19701 --- [ main] o.a.tutorial.restapi.ListRenditionsCmd : Listing versions for file node ID 0492460b-6269-4ca1-9668-0d934d2f3370
2021-04-29 13:58:25.703 INFO 19701 --- [ main] o.a.tutorial.restapi.ListRenditionsCmd : Node rendition: class Rendition {
id: avatar
content: class ContentInfo {
mimeType: image/png
mimeTypeName: PNG Image
sizeInBytes: null
encoding: null
}
status: NOT_CREATED
}
2021-04-29 13:58:25.703 INFO 19701 --- [ main] o.a.tutorial.restapi.ListRenditionsCmd : Node rendition: class Rendition {
id: avatar32
content: class ContentInfo {
mimeType: image/png
mimeTypeName: PNG Image
sizeInBytes: null
encoding: null
}
status: NOT_CREATED
}
2021-04-29 13:58:25.703 INFO 19701 --- [ main] o.a.tutorial.restapi.ListRenditionsCmd : Node rendition: class Rendition {
id: doclib
content: class ContentInfo {
mimeType: image/png
mimeTypeName: PNG Image
sizeInBytes: 222
encoding: UTF-8
}
status: CREATED
}
2021-04-29 13:58:25.703 INFO 19701 --- [ main] o.a.tutorial.restapi.ListRenditionsCmd : Node rendition: class Rendition {
id: imgpreview
content: class ContentInfo {
mimeType: image/jpeg
mimeTypeName: JPEG Image
sizeInBytes: null
encoding: null
}
status: NOT_CREATED
}
2021-04-29 13:58:25.703 INFO 19701 --- [ main] o.a.tutorial.restapi.ListRenditionsCmd : Node rendition: class Rendition {
id: medium
content: class ContentInfo {
mimeType: image/jpeg
mimeTypeName: JPEG Image
sizeInBytes: null
encoding: null
}
status: NOT_CREATED
}
2021-04-29 13:58:25.703 INFO 19701 --- [ main] o.a.tutorial.restapi.ListRenditionsCmd : Node rendition: class Rendition {
id: pdf
content: class ContentInfo {
mimeType: application/pdf
mimeTypeName: Adobe PDF Document
sizeInBytes: 8472
encoding: UTF-8
}
status: CREATED
}
We can see the renditions id, such as pdf. Some renditions are for things you see in the UI, such as thumbnail and preview of document.