So I'm circling back on a problem I tackled a few years ago, as I needed to update the Chatter API version that I'm using, and in doing so need to rework some code that touched the nasty hack in question.
I want to display a thumbnail for images in chatter posts, these can now be inline in a post, and the data for the relevant part of the feed item looks like this:
{
"altText": "acheron",
"contentSize": 703924,
"fileExtension": "jpg",
"imageDetails": {
"height": 949,
"imageFormat": "JPG",
"orientation": "1",
"width": 1280
},
"text": "\n[Image: acheron]\n",
"thumbnails": {
"fileId": "0691D000000CJjBQAW",
"previews": [
{
"format": "ThumbnailTiny",
"previewUrlCount": 1,
"previewUrls": [
{
"pageNumber": 0,
"previewUrl": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/rendition?type=THUMB120BY90&page=0"
}
],
"status": "Available",
"url": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/previews/tiny-thumbnail"
},
{
"format": "Thumbnail",
"previewUrlCount": 1,
"previewUrls": [
{
"pageNumber": 0,
"previewUrl": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/rendition?type=THUMB240BY180&page=0"
}
],
"status": "Available",
"url": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/previews/thumbnail"
},
{
"format": "ThumbnailBig",
"previewUrlCount": 1,
"previewUrls": [
{
"pageNumber": 0,
"previewUrl": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/rendition?type=THUMB720BY480&page=0"
}
],
"status": "Available",
"url": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/previews/big-thumbnail"
}
],
"url": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/previews",
"versionNumber": "1"
},
"type": "InlineImage",
"url": "/services/data/v44.0/connect/files/0691D000000CJjBQAW/content?versionNumber=1"
}
As you can see, all of the URLs are intended to be called via the Connect API, but as per my previous issue, these don't work as img
tag src
attributes as the browser doesn't send the relevant authentication info when making the request, and I don't really want to download all of the files directly in this manner as it's just a layer of extra complication for the client application to deal with. Note, all the URLs contain the Id of the Content record, starting with 069.
It's possible to get an image URL for which the browser sends an auth cookie, the built-in Visualforce <chatter:feed>
tag generates all the markup for a feed and uses URLS like this for the images:
/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=0681D000000CHnk&operationContext=CHATTER
This uses the ContentVersion Id of the latest version record (prefix 068), and this can be found through various queries:
SELECT Id FROM ContentVersion where IsLatest = true and contentdocumentid = '0691D000000CJjBQAW'
or
SELECT Id, LatestPublishedVersionId FROM ContentDocument where Id = '0691D000000CJjBQAW'
The Question
Is there a way I can generate /sfc/servlet.shepherd
URL using only data from the Connect API? I'm thinking not and that I'll have to make perform a query and get the ContentVersion IDs for all of the images I want to display.