class_docstr: In-memory file manager for MediaFile objects.
  
  This keeps track of:
  - Which files exist, and what their IDs are. This is important so we can
    serve files by ID -- that's the whole point of this class!
  - Which files are being used by which AppSession (by ID). This is
    important so we can remove files from memory when no more sessions need
    them.
  - The exact location in the app where each file is being used (i.e. the
    file's "coordinates"). This is is important so we can mark a file as "not
    being used by a certain session" if it gets replaced by another file at
    the same coordinates. For example, when doing an animation where the same
    image is constantly replace with new frames. (This doesn't solve the case
    where the file's coordinates keep changing for some reason, though! e.g.
    if new elements keep being prepended to the app. Unlikely to happen, but
    we should address it at some point.)
class_docstr_tok: ["In-memory","file","manager","for","MediaFile","objects",".","This","keeps","track","of",":","-","Which","files","exist",",","and","what","their","IDs","are",".","This","is","important","so","we","can","serve","files","by","ID","--","that","'s","the","whole","point","of","this","class","!","-","Which","files","are","being","used","by","which","AppSession","(","by","ID",")",".","This","is","important","so","we","can","remove","files","from","memory","when","no","more","sessions","need","them",".","-","The","exact","location","in","the","app","where","each","file","is","being","used","(","i.e",".","the","file","'s","``","coordinates","''",")",".","This","is","is","important","so","we","can","mark","a","file","as","``","not","being","used","by","a","certain","session","''","if","it","gets","replaced","by","another","file","at","the","same","coordinates",".","For","example",",","when","doing","an","animation","where","the","same","image","is","constantly","replace","with","new","frames",".","(","This","does","n't","solve","the","case","where","the","file","'s","coordinates","keep","changing","for","some","reason",",","though","!","e.g",".","if","new","elements","keep","being","prepended","to","the","app",".","Unlikely","to","happen",",","but","we","should","address","it","at","some","point",".",")"]
docstr: Add a new MediaFile with the given parameters and return its URL.
  
  If an identical file already exists, return the existing URL
  and registers the current session as a user.
  
  Safe to call from any thread.
  
  Parameters
  ----------
  path_or_data : bytes or str
      If bytes: the media file's raw data. If str: the name of a file
      to load from disk.
  mimetype : str
      The mime type for the file. E.g. "audio/mpeg".
      This string will be used in the "Content-Type" header when the file
      is served over HTTP.
  coordinates : str
      Unique string identifying an element's location.
      Prevents memory leak of "forgotten" file IDs when element media
      is being replaced-in-place (e.g. an st.image stream).
      coordinates should be of the form: "1.(3.-14).5"
  file_name : str or None
      Optional file_name. Used to set the filename in the response header.
  is_for_static_download: bool
      Indicate that data stored for downloading as a file,
      not as a media for rendering at page. [default: False]
  
  Returns
  -------
  str
      The url that the frontend can use to fetch the media.
  
  Raises
  ------
  If a filename is passed, any Exception raised when trying to read the
  file will be re-raised.
docstr_tok: ["Add","a","new","MediaFile","with","the","given","parameters","and","return","its","URL",".","If","an","identical","file","already","exists",",","return","the","existing","URL","and","registers","the","current","session","as","a","user",".","Safe","to","call","from","any","thread",".","Parameters","--","--","--","--","--","path_or_data",":","bytes","or","str","If","bytes",":","the","media","file","'s","raw","data",".","If","str",":","the","name","of","a","file","to","load","from","disk",".","mimetype",":","str","The","mime","type","for","the","file",".","E.g",".","``","audio\/mpeg","''",".","This","string","will","be","used","in","the","``","Content-Type","''","header","when","the","file","is","served","over","HTTP",".","coordinates",":","str","Unique","string","identifying","an","element","'s","location",".","Prevents","memory","leak","of","``","forgotten","''","file","IDs","when","element","media","is","being","replaced-in-place","(","e.g",".","an","st.image","stream",")",".","coordinates","should","be","of","the","form",":","``","1",".","(","3.-14",")",".5","''","file_name",":","str","or","None","Optional","file_name",".","Used","to","set","the","filename","in","the","response","header",".","is_for_static_download",":","bool","Indicate","that","data","stored","for","downloading","as","a","file",",","not","as","a","media","for","rendering","at","page",".","[","default",":","False","]","Returns","--","--","--","-","str","The","url","that","the","frontend","can","use","to","fetch","the","media",".","Raises","--","--","--","If","a","filename","is","passed",",","any","Exception","raised","when","trying","to","read","the","file","will","be","re-raised","."]
code: def add(
      self,
      path_or_data: Union[bytes, str],
      mimetype: str,
      coordinates: str,
      file_name: Optional[str] = None,
      is_for_static_download: bool = False,
  ) -> str:
      """Add a new MediaFile with the given parameters and return its URL.
  
      If an identical file already exists, return the existing URL
      and registers the current session as a user.
  
      Safe to call from any thread.
  
      Parameters
      ----------
      path_or_data : bytes or str
          If bytes: the media file's raw data. If str: the name of a file
          to load from disk.
      mimetype : str
          The mime type for the file. E.g. "audio/mpeg".
          This string will be used in the "Content-Type" header when the file
          is served over HTTP.
      coordinates : str
          Unique string identifying an element's location.
          Prevents memory leak of "forgotten" file IDs when element media
          is being replaced-in-place (e.g. an st.image stream).
          coordinates should be of the form: "1.(3.-14).5"
      file_name : str or None
          Optional file_name. Used to set the filename in the response header.
      is_for_static_download: bool
          Indicate that data stored for downloading as a file,
          not as a media for rendering at page. [default: False]
  
      Returns
      -------
      str
          The url that the frontend can use to fetch the media.
  
      Raises
      ------
      If a filename is passed, any Exception raised when trying to read the
      file will be re-raised.
      """
  
      session_id = _get_session_id()
  
      with self._lock:
          kind = (
              MediaFileKind.DOWNLOADABLE
              if is_for_static_download
              else MediaFileKind.MEDIA
          )
          file_id = self._storage.load_and_get_id(
              path_or_data, mimetype, kind, file_name
          )
          metadata = MediaFileMetadata(kind=kind)
  
          self._file_metadata[file_id] = metadata
          self._files_by_session_and_coord[session_id][
              coordinates
          ] = file_id
  
          return self._storage.get_url(file_id)
  
file_path: streamlit/lib/streamlit/runtime/media_file_manager.py
imports: import collections
  import threading
  from typing import Dict, Optional, Set, Union
  from streamlit.logger import get_logger
  from streamlit.runtime.media_file_storage import MediaFileKind, MediaFileStorage
label_desc: Use image node_id 6 for calling the MediaFileManager obj's underlying member method code with example usage: obj.add(path_or_data, mimetype, coordinates, file_name, is_for_static_download) and returns: self