public static function urlencodeFilename($file) {
    $parts = explode('/', $file);
    $result = [];
    foreach ($parts as $part) {
      $result[] = rawurlencode($part);
    }
    return join('/', $result);
  }