How are v2 attachments supposed to be accessed in 2023.06?

Previously attachments could be loaded in the backend using AttachmentLoader#loadAttachment(). But it has been deprecated and com.mgmtp.a12.dataservices.attachment.v2.AttachmentService should be used as a replacement according to the deprecation information.

I’ve searched for a way to access the content of the attachments directly in the backend and I did not find a satisfying solution (this really basic use case is not mentioned in the documentation):

  1. com.mgmtp.a12.dataservices.attachment.v2.AttachmentService only provides a download url via #getAttachmentUrl(). Calling this url seems highly inefficient for accessing the files internally in the backend.

  2. I could try to use com.mgmtp.a12.contentstore.service.ContentStoreService, but even there I would need to first create a download url, extract the download id from it and call ContentStoreService#getContent() with it.

  3. Calling com.mgmtp.a12.contentstore.content.internal.ContentService#getByContentIdAndPersistentType() directly may be a solution, but this is marked as internal, so probably not the intended way

So what is the intended way to access the attachments?

I successfully implemented my second suggestion: (written in Kotlin, but should be similar for Java)

fun fetchAttachmentBytes(contentId: String): ByteArray {
    val ticketId = contentStoreService.requestContentUrl(contentId, 60L).substringAfterLast('/')
    return contentStoreService.getContent(ticketId).contentSupplier.get().use { it.readBytes() }
}

its not a nice solution but practical and (probably) necessary like this until A12 provides an out of the box solution.

Maybe this helps if somebody has the same problem :smiley:

With Attachment 2.0 there is no support for direct download of attachment anymore.

Instead, it is always required to first retrieve the URL (for attachment or thumbnail) and then use this URL for download.

If there is the need for other ways of access a new requirement would have to be filed.