getContentThumbnail method
{{% boxes/note %}}
Replaced by GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId}
(requires authentication).
{{% /boxes/note %}}
Download a thumbnail of content from the content repository. See the Thumbnails section for more information.
{{% boxes/warning %}}
{{% changed-in v="1.11" %}} This endpoint MAY return 404 M_NOT_FOUND
for media which exists, but is after the server froze unauthenticated
media access. See Client Behaviour for more
information.
{{% /boxes/warning %}}
serverName The server name from the mxc:// URI (the authority component).
mediaId The media ID from the mxc:// URI (the path component).
width The desired width of the thumbnail. The actual thumbnail may be
larger than the size specified.
height The desired height of the thumbnail. The actual thumbnail may be
larger than the size specified.
method The desired resizing method. See the Thumbnails
section for more information.
allowRemote Indicates to the server that it should not attempt to fetch the media if
it is deemed remote. This is to prevent routing loops where the server
contacts itself.
Defaults to true if not provided.
timeoutMs The maximum number of milliseconds that the client is willing to wait to
start receiving data, in the case that the content has not yet been
uploaded. The default value is 20000 (20 seconds). The content
repository SHOULD impose a maximum value for this parameter. The
content repository MAY respond before the timeout.
allowRedirect Indicates to the server that it may return a 307 or 308 redirect
response that points at the relevant media content. When not explicitly
set to true the server must return the media content itself.
animated Indicates preference for an animated thumbnail from the server, if possible. Animated
thumbnails typically use the content types image/gif, image/png (with APNG format),
image/apng, and image/webp instead of the common static image/png or image/jpeg
content types.
When true, the server SHOULD return an animated thumbnail if possible and supported.
When false, the server MUST NOT return an animated thumbnail. For example, returning a
static image/png or image/jpeg thumbnail. When not provided, the server SHOULD NOT
return an animated thumbnail.
Servers SHOULD prefer to return image/webp thumbnails when supporting animation.
When true and the media cannot be animated, such as in the case of a JPEG or PDF, the
server SHOULD behave as though animated is false.
Implementation
@deprecated
Future<FileResponse> getContentThumbnail(
String serverName,
String mediaId,
int width,
int height, {
Method? method,
bool? allowRemote,
int? timeoutMs,
bool? allowRedirect,
bool? animated,
}) async {
final requestUri = Uri(
path:
'_matrix/media/v3/thumbnail/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}',
queryParameters: {
'width': width.toString(),
'height': height.toString(),
if (method != null) 'method': method.name,
if (allowRemote != null) 'allow_remote': allowRemote.toString(),
if (timeoutMs != null) 'timeout_ms': timeoutMs.toString(),
if (allowRedirect != null) 'allow_redirect': allowRedirect.toString(),
if (animated != null) 'animated': animated.toString(),
},
);
final request = Request('GET', baseUri!.resolveUri(requestUri));
final response = await httpClient.send(request);
final responseBody = await response.stream.toBytes();
if (response.statusCode != 200) unexpectedResponse(response, responseBody);
return FileResponse(
contentType: response.headers['content-type'],
data: responseBody,
);
}