Hello,
I am trying to set a custom thumbnail for an asset. Is there some documentation about it? I have tried the following:
@EventListener
public void afterCreateListener(AttachmentAfterCreateEvent event) throws IOException, InterruptedException {
String path = event.getAttachment().getAbsolutePath();
// only work with PDF files
if (!path.endsWith(".pdf")) return;
// generate thumbnail from PDF with ImageMagick
ProcessBuilder builder = new ProcessBuilder("convert", path + "[0]", "output.png");
Process process = builder.start();
process.waitFor();
// get thumbnail
File thumbnail = new File("output.png");
System.out.println(thumbnail.getAbsolutePath());
// set the thumbnail
event.setThumbnailBig(thumbnail);
event.setThumbnailSmall(thumbnail);
System.out.println("Created thumbnails for attachmentId=" + event.getAttachmentId());
}
The creation of the output.png works without problems and is correct, the file also exists.
The output is as follows:
[..] ThumbnailGenerator : Thumbnail for 8f54d7e7-261e-40c8-a7f2-dabebde9d561.pdf can't be [..]
[..] ThumbnailGenerator : Thumbnail for 8f54d7e7-261e-40c8-a7f2-dabebde9d561.pdf can't be generated since it's not an image or unsupported format.
Created thumbnails for attachmentId=8f54d7e7-261e-40c8-a7f2-dabebde9d56 (my listener)
But the thumbnail is not added to the asset. Is there something else I need to do?
Hi @anon11273509 ,
Currently DS does not allow custom creation of thumbnails. Thumbnails are created automatically using net.coobird:thumbnailator library. Please create a ticket to support custom thumbnail creation and we will add a support for it.
This answer is valid for Data services 30.1 - 35.0.0
That’s why I have implemented the custom thumbnail creation by myself - that’s not a problem for me. I just want to know, whether I can set the thumbnail through the AttachmentAfterCreateEvent. If that’s not possible, why is the event.SetThumbnail... method even available?
Hi @anon11273509,
ThumbnailGenerator class is only available in release lines 30.1.x and 32.2.x both that will be dropped in a couple of months. AttachmentAfterCreateEvent does not have setters for thumbnails in versions 34.2 and in 35.0, In version 34.2.0 we have introduced different attachment handling which allows custom persistence for attachments, therefore this event is not usable for changing the attachments because you must be store-aware. We will investigate on how to enable custom creation of thumbnails but based on our analysis this will probably require a new event to be published specifically for thumbnails. Payload of AttachmentAfterCreateEvent is not used in our processing because all persisting is done already, therefore this event can be used for auditing, changing HTTP responses or final checks that can trigger rollback.
Hi @anon11273509,
Custom thumbnail generation will be delivered only in 2023.06 because overview engine is not prepared to render thumbnails that have not originated from image/jpeg or image/png mime-types. This bug will be fixed in overview engine in 2023.02 so we can enable custom thumbnail creation only afterwards in 2023.06 it would not make sense to do it before because your generated thumbnails will not be visible in overviews. I am sorry for inconvenience