class_docstr: Implements the POST /upload_file endpoint.
class_docstr_tok: ["Implements","the","POST","\/upload_file","endpoint","."]
docstr: Receive an uploaded file and add it to our UploadedFileManager.
docstr_tok: ["Receive","an","uploaded","file","and","add","it","to","our","UploadedFileManager","."]
code: def put(self, **kwargs):
      """Receive an uploaded file and add it to our UploadedFileManager."""
  
      args: Dict[str, List[bytes]] = {}
      files: Dict[str, List[Any]] = {}
  
      session_id = self.path_kwargs["session_id"]
      file_id = self.path_kwargs["file_id"]
  
      tornado.httputil.parse_body_arguments(
          content_type=self.request.headers["Content-Type"],
          body=self.request.body,
          arguments=args,
          files=files,
      )
  
      try:
          if not self._is_active_session(session_id):
              raise Exception(f"Invalid session_id")
      except Exception as e:
          self.send_error(400, reason=str(e))
          return
  
      uploaded_files: List[UploadedFileRec] = []
  
      for _, flist in files.items():
          for file in flist:
              uploaded_files.append(
                  UploadedFileRec(
                      file_id=file_id,
                      name=file["filename"],
                      type=file["content_type"],
                      data=file["body"],
                  )
              )
  
      if len(uploaded_files) != 1:
          self.send_error(
              400,
              reason=f"Expected 1 file, but got {len(uploaded_files)}",
          )
          return
  
      self._file_mgr.add_file(
          session_id=session_id, file=uploaded_files[0]
      )
      self.set_status(204)
  
file_path: streamlit/lib/streamlit/web/server/upload_file_request_handler.py
imports: from typing import Any, Callable, Dict, List
  import tornado.httputil
  import tornado.web
  from streamlit import config
  from streamlit.logger import get_logger
  from streamlit.runtime.memory_uploaded_file_manager import MemoryUploadedFileManager
  from streamlit.runtime.uploaded_file_manager import UploadedFileManager, UploadedFileRec
  from streamlit.web.server import routes, server_util
label_desc: Use image node_id 4 for calling the UploadFileRequestHandler obj's underlying member method code with example usage: obj.put() without return types