downloadMedia static method
Offline media: explicitly download + cache message's attachment.
Honored in both media-caching modes (an explicit download always wins). Re-signs an expired presigned URL automatically. Reports progress (0..100 when the length is known) and fails with a typed MediaException — e.g. MediaErrorCode.offlineNotCached — rather than a raw HTTP error.
Implementation
static Future<void> downloadMedia(
BaseMessage message, {
MediaCallbackListener? listener,
}) async {
try {
final path = await OfflineRuntime.instance.downloadMedia(
message,
onProgress: listener?.onProgress,
);
listener?.onSuccess?.call(path);
} on MediaException catch (e) {
listener?.onError?.call(e);
} catch (e) {
listener?.onError?.call(
MediaException(MediaErrorCode.downloadFailed, e.toString()),
);
}
}