getCachedFileFromUri

fun getCachedFileFromUri(context: Context, attachmentMetaData: AttachmentMetaData): File?

Retrieves or creates a cached copy of a file from the given attachment metadata.

This method handles two scenarios:

  1. If AttachmentMetaData.file is already set, it returns the file directly

  2. If only AttachmentMetaData.uri is available, it copies the content to a cache file

The cached file is stored in a unique timestamped folder within the app's cache directory to prevent naming conflicts. The file name is derived from the attachment's title with proper extension handling.

Return

A File object pointing to the cached file, or null if both file and URI are null.

Parameters

context

The Android context used to access the content resolver and cache directory.

attachmentMetaData

The attachment metadata containing either a file or URI reference.

Throws

If there's an error reading from the URI or writing to cache.