from

fun from(uri: Uri, name: String? = null, size: Long? = null, mimeType: String? = null): AIMessageAttachment

An attachment of the file at uri, of the kind its type says: an image for an image this device can show, and a file otherwise. Such as for the files the person picked.

The type is mimeType, else the extension of name or of the file uri ends in. A photo picker or MediaStore content:// URI has no extension, so pass contentResolver.getType(uri) as mimeType for it, or it is a file. A mimeType that only says the type is unknown, such as application/octet-stream, leaves it to the extension. JPEG, PNG, WebP, GIF and BMP images show on every Android version, HEIF and HEIC from Android 9, and AVIF from Android 12. Other images, such as SVG, are files.

Parameters

uri

Where the file is: on the web, or on this device, such as a content:// URI the person picked.

name

Its name, such as the file's.

size

Its size, in bytes.

mimeType

Its media type, such as image/png.