fromExternalFilesDir

fun FileArtifactService.Companion.fromExternalFilesDir(context: Context, subDir: String = FileArtifactService.DEFAULT_ARTIFACTS_SUBDIR): FileArtifactService

Builds a FileArtifactService rooted at <app-specific external files dir>/<subDir>.

This is the recommended factory for artifacts: app-specific external storage (Context.getExternalFilesDir) persists until the app is uninstalled and is not swept by the system cache cleaner, and needs no runtime permission. It is still app-private.

External storage can be unavailable (e.g. unmounted), in which case Context.getExternalFilesDir returns null and this throws IllegalStateException. The location is chosen explicitly rather than silently falling back, so artifacts always live at a stable path; callers that want internal storage should use fromInternalFilesDir, and callers that want their own fallback can write it explicitly, e.g. runCatching { fromExternalFilesDir(ctx) }.getOrElse { fromInternalFilesDir(ctx) }.

Multiple agents in the same app can isolate their artifacts by passing a distinct subDir. Uses Context.getApplicationContext internally to avoid leaking an Activity.

Throws

if external storage is currently unavailable.