getPublicUrl method

String getPublicUrl(
  1. String path, {
  2. TransformOptions? transform,
})

Retrieve URLs for assets in public buckets

path is the file path to be downloaded, including the current file name. For example getPublicUrl('folder/image.png').

transform adds image transformations parameters to the generated url.

Implementation

String getPublicUrl(
  String path, {
  TransformOptions? transform,
}) {
  final finalPath = _getFinalPath(path);

  final wantsTransformation = transform != null;
  final renderPath = wantsTransformation ? 'render/image' : 'object';
  final transformationQuery = transform?.toQueryParams;

  var publicUrl = Uri.parse('$url/$renderPath/public/$finalPath');

  publicUrl = publicUrl.replace(queryParameters: transformationQuery);

  return publicUrl.toString();
}