publicUrlFor method

String publicUrlFor({
  1. required String bucket,
  2. required String path,
  3. KoolbaseImageTransform? transform,
  4. String? preset,
})

Build the stable public CDN URL for a file in a public bucket, using the project identity the SDK learned at bootstrap — the normal runtime form of publicUrl, which needs no projectId argument.

Throws KoolbaseStorageProjectIdentityException while identity is unavailable (first bootstrap has never completed — e.g. a fresh install starting offline). The throw also nudges a background bootstrap refresh, so a later call in the same session succeeds once connectivity returns. This is a DIFFERENT state from a null public URL on KoolbaseObject.publicUrl: null means the project is known and the object simply has no public URL (private bucket).

preset names one of the project's image presets (Storage → Presets): the URL is then the named-preset form (publicUrlWithPreset), sized at the edge as the preset says, and transform is not used.

Implementation

String publicUrlFor({
  required String bucket,
  required String path,
  KoolbaseImageTransform? transform,
  String? preset,
}) {
  final pid = _projectIdProvider?.call() ?? '';
  if (pid.isEmpty) {
    _nudgeBootstrap?.call();
    throw const KoolbaseStorageProjectIdentityException();
  }
  if (preset != null && preset.isNotEmpty) {
    return publicUrlWithPreset(
      projectId: pid,
      presetName: preset,
      bucket: bucket,
      path: path,
    );
  }
  return publicUrl(
    projectId: pid,
    bucket: bucket,
    path: path,
    transform: transform,
  );
}