getContentThumbnail method

Future<FileResponse> getContentThumbnail(
  1. String serverName,
  2. String mediaId,
  3. int width,
  4. int height, {
  5. Method? method,
  6. bool? allowRemote,
})

Download a thumbnail of content from the content repository. See the Thumbnails section for more information.

serverName The server name from the mxc:// URI (the authoritory 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.

Implementation

Future<FileResponse> getContentThumbnail(
    String serverName, String mediaId, int width, int height,
    {Method? method, bool? allowRemote}) 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(),
      });
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  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);
}