I have C2S and S2S apps in development, and I’m working on a way to allow users to attach images to documents they send. The images will be stored in S3-compatible storage, so a URL will suffice to accessing them in AP. I’m planning on representing them using the Attachment structure. To help with performance and minimize bandwidth, I’d like to serve and show a preview of the images uploaded where appropriate. I would like my server to interoperate well with other servers, and the AP specification is so wide open it’s hard to know what kinds of messages my client should expect to have to display.
My question is about structuring images. For now, I’ve been thinking about a structure like this one (in JavaScript, but close enough to JSON for you to get the idea):
{
type: 'Note',
content: 'Hello, world!',
attributedTo: 'https://me.example.com/actor',
to: 'https://me.example.com/actor/followers',
attachment: {
type: 'Image',
url: {
type: "Link",
href: 'https://images.example.com/image.jpeg',
width: 5120,
height: 2880,
mediaType: 'image/jpeg',
preview: {
type: "Link",
href: 'https://images.example.com/image-preview.jpeg',
width: 512,
height: 288,
mediaType: 'image/jpeg'
}
}
}
}
But I recognize that there are myriad other ways to represent the same data. The attachment could simply be a Link
with a mediaType
. It needn’t be an Image
but could simply be a Document
, as Mastodon does. The url
needn’t be a single object, but an array of multiple links with different width
and height
from which the client should select. There needn’t be a URL at all, and the image could be encoded into the content
field, which is actually the closest to the definition from the attachment
spec:
Identifies a resource attached or related to an object that potentially requires special handling. The intent is to provide a model that is at least semantically similar to attachments in email.
I don’t want to develop my application to handle every possible representation it might encounter; I’d rather use my finite time for developing features that will actually be used. At the same point, I’d like to strike a reasonable balance of interoperability. The specification is so wide open as to be nearly useless in deciding what formats one should expect to support.