getContentOverrideName method
This will download content from the content repository (same as the previous endpoint) but replace the target file name with the one provided by the caller.
serverName
The server name from the mxc://
URI (the authoritory component)
mediaId
The media ID from the mxc://
URI (the path component)
fileName
A filename to give in the Content-Disposition
header.
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> getContentOverrideName(
String serverName, String mediaId, String fileName,
{bool? allowRemote}) async {
final requestUri = Uri(
path:
'_api/media/v3/download/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}/${Uri.encodeComponent(fileName)}',
queryParameters: {
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);
}