docstr: Upload a file while tracking its progress.
docstr_tok: ["Upload","a","file","while","tracking","its","progress","."]
code: def upload_file(self, file):
      """Upload a file while tracking its progress."""
      # 1: Track metadata about the file
      filename = file.filename
      uploaded_file = self.get_random_filename()
      meta_file = uploaded_file + ".meta"
      self.uploaded_files[filename] = {
          "progress": (0, None),
          "done": False,
      }
  
      # 2: Create a stream and write bytes of
      # the file to the disk under `uploaded_file` path.
      with open(self.get_filepath(uploaded_file), "wb") as out_file:
          content = file.read(self.chunk_size)
          while content:
              # 2.1 Write the file bytes
              size = out_file.write(content)
  
              # 2.2 Update the progress metadata
              self.uploaded_files[filename]["progress"] = (
                  self.uploaded_files[filename]["progress"][0] + size,
                  None,
              )
              # 4: Read next chunk of data
              content = file.read(self.chunk_size)
  
      # 3: Update metadata that the file has been uploaded.
      full_size = self.uploaded_files[filename]["progress"][0]
      self.drive.put(self.get_filepath(uploaded_file))
      self.uploaded_files[filename] = {
          "progress": (full_size, full_size),
          "done": True,
          "uploaded_file": uploaded_file,
      }
  
      # 4: Write down the metadata about the file to the disk
      meta = {
          "original_path": filename,
          "display_name": os.path.splitext(filename)[0],
          "size": full_size,
          "drive_path": uploaded_file,
      }
      with open(self.get_filepath(meta_file), "w") as f:
          json.dump(meta, f)
  
      # 5: Put the file to the drive.
      # It means other components can access get or list them.
      self.drive.put(self.get_filepath(meta_file))
      return meta
  
imports: import json
  import os
  import tarfile
  import uuid
  import zipfile
  from pathlib import Path
  from lightning.app import LightningWork, LightningApp
  from lightning.app.storage import Drive
  import requests
  from lightning import LightningWork
  from lightning import LightningApp, LightningFlow
  from lightning.app.runners import MultiProcessRuntime
  from lightning.app.testing import run_app_in_cloud
label_desc: Use image node_id 4 for calling the FileServer obj's underlying member method code with example usage: obj.upload_file(file) and returns: meta