import base64


def buffer_to_B64(img_buffer):
  """Encode image buffer as base64 string.

  :param img_buffer: image buffer
  :type img_buffer: buffer
  :return: base64 string of image buffer
  :rtype: str
  """
  # make sure buffer is at beginning
  img_buffer.seek(0)
  data = img_buffer.read()
  b64_from_data = base64.b64encode(data)
  return b64_from_data