encodeFileName function

String encodeFileName(
  1. String url
)

Generate a unique, reversible filename from a URL

Implementation

String encodeFileName(String url) {
  // Remove http://, https://, and www.
  String cleanedUrl = url.replaceFirst(RegExp(r'^https?:\/\/(www\.)?'), '');

  // Base64 URL-safe encoding without padding
  return base64UrlEncode(utf8.encode(cleanedUrl)).replaceAll('=', '');
}