File Manager

File Manager is a Gramex app used to upload, download, rename, delete and annotate files within a Gramex application.

Usage

FileManager can be imported in a Gramex app as follows:

  import:
    filemanager:
      path: $GRAMEXAPPS/filemanager/gramex.yaml
      YAMLURL: $YAMLURL/filemanager/
  
This mounts the FileManager page at /filemanager/. For each DriveHandler endpoint configured in your Gramex app, the FileManager page shows a FormHandler table of files stored in that drive. This table can be used to:

FileManager Options

FileManager can be configured by using options under FILEMANAGER_KWARGS in gramex.yaml as follows:

  import:
    filemanager:
      path: $GRAMEXAPPS/filemanager/gramex.yaml
      YAMLURL: $YAMLURL/filemanager/
      FILEMANAGER_KWARGS:
        drives: ['drive1', 'drive2']              # Show only these drives in the FileManager page
        title: "MyAwesomeFileManager"             # Title of the FileManager page
        logo: $YAMLPATH/data/assets/gramener.png  # Logo for the FileManager page
        theme: ...                                # Bootstrap theme for the FileManager page.
  

Drive Handler

DriveHandler allows uploading, downloading, renaming, deletion and annotation of files in a Gramex application.

Usage

Use DriveHandler in Gramex app as follows:

url:
  pattern: /$YAMLURL/mydrive
  handler: DriveHandler
  kwargs:
    path: $YAMLPATH/path/to/drive  # folder where files are stored
    user_fields: [id, role, hd]         # user attributes to store
    tags: [tag]                         # <input name=""> to store
    allow: [.doc, .docx]            # Only allow these files
    ignore: [.pdf]                 # Exclude these files
    max_file_size: 100000                # Files must be smaller than this
    redirect:                           # After uploading the file,
        query: next                     #   ... redirect to ?next=
        url: /$YAMLURL/                 #   ... else to this directory
This endpoint is a FormHandler that allows:

Embedding FileManager

Just like FormHandler, the FileManager component can be embedded in any <div> element, as follows:

  <!-- Include Dropzone and moment -->
  <link rel="stylesheet" href="ui/dropzone/dist/min/dropzone.min.css">
  <script src="ui/dropzone/dist/min/dropzone.min.js"></script>
  <script src="ui/moment/min/moment-with-locales.min.js"></script>
  <div class="filemanager" data-src="drive"></div>
  <script>
    Dropzone.autodiscover = false
    $('.filemanager').filemanager({
      pageSize: 4,
      data: ...,
      columns: [
        {name: "foo"},
        {name: "bar"}
      ]
      // FormHandler options
    })
  </script>