Skip to main content

flask-file-explorer

Why

This tool is just a simple flask tool to view a configurable file system in flask. Handy for docker deployments, debugging, validating something is in the right place etc...

There is no security built into it, so you have to bring your own. See Flask-Login with a blueprint as an example.

Features

Todos ToDones:

  • Upload forms aware of current directory
  • Drag & Drop Upload
  • Visual treatment of current directory
  • Folder and File listing
  • Blueprint
  • Dynamic data retrieval
  • Collapsing tree structure
  • Remove closed directory tree
  • Secure file browsing and uploads
  • Custom theming and embedding

A quick and easy web based file explorer

Flask-file-explorer supports navigating through directories, viewing files, downloading / uploading files

  • File System Explorer
Flask File Explorer
  • File Viewer
Flask File Viewer

Installation

Standard install

poetry add flask-file-explorer
# or
pip install flask-file-explorer
# or 
poetry add git+https://github.com/thevgergroup/flask-file-explorer

Within your flask app, simply add the file explorer blueprint and specify the directory to limit access to

'''
This is the main file of the Flask application.
It registers the file_explorer blueprint and starts the server.
'''
from flask import Flask

from flask_file_explorer.file_explorer import file_explorer_bp  # The blueprint code
from flask_file_explorer.filters import register_filters        # Filters used in the viewer

app = Flask(__name__)

app.config["FFE_BASE_DIRECTORY"] = 'flask_file_explorer/static'         # The directory the explorer is limited to
app.register_blueprint(file_explorer_bp, url_prefix='/file-explorer')   # Add the blueprint to the flask app
register_filters(app)                                                   # Register the filter



if __name__ == '__main__':
    app.run()

Once your start your app, you should be able to go to http://..../file-explorer/browse

Security

There are a couple of security items

  1. All file paths are verified as being in the FFE_BASE_DIRECTORY
    • The absolute path is used to verify the file and it's relativity to the FFE_BASE_DIRECTORY
  2. Authentication and Authorization are a bring your own model
    • Example provided below

Flask-Login with a blueprint

from flask import Flask, Response, redirect, url_for, request, session, abort
from flask_login import LoginManager, UserMixin, current_user, \
                                login_required, login_url, login_user, logout_user 
                                
from flask_file_explorer.file_explorer import file_explorer_bp  # The blueprint code
from flask_file_explorer.filters import register_filters        # Filters used in the viewer


app = Flask(__name__)


app.config["FFE_BASE_DIRECTORY"] = 'templates'         # The directory the explorer is limited to
app.register_blueprint(file_explorer_bp, url_prefix='/file-explorer')   # Add the blueprint to the flask app
register_filters(app)                                                   # Register the filter

@app.before_request
def check_for_login():
    # Define a list of protected routes within the third-party blueprint
    protected_routes = '/file-explorer'
    if request.path.startswith(protected_routes):
        if not current_user.is_authenticated:
            # Redirect to login page if the user is not authenticated
            return redirect(login_url('login', request.url))

Metadata

Release files for flask-file-explorer 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-file-explorer 0.1.1
File Size Uploaded
flask_file_explorer-0.1.1.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-file-explorer 0.1.1
File Interpreter ABI Platform
flask_file_explorer-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / flask_file_explorer-0.1.1.tar.gz

Download URL flask_file_explorer-0.1.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8d97a1f0f0d72a6fda2703fb94d9b867687a5e00eef312bb7f8d77f965546ff0
BLAKE2b-256 checksum
How to use checksums
f7af5bbd79b08c0674ba570798f98edb5f38dc13d59060f899b70f599dc4afac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / flask_file_explorer-0.1.1-py3-none-any.whl

Download URL flask_file_explorer-0.1.1-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a46eaaca0c4a8af92a4455b4f5b26367ef395d2f966927899b48cdc72060d609
BLAKE2b-256 checksum
How to use checksums
2e7db9a1e4d7b687e42a706c85168974a3eb889e3aa110d9695e0f6de549f323
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page