A flask based file explorer
Project description
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
- 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
- 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
- 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))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flask_file_explorer-0.1.1.tar.gz
.
File metadata
- Download URL: flask_file_explorer-0.1.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d97a1f0f0d72a6fda2703fb94d9b867687a5e00eef312bb7f8d77f965546ff0 |
|
MD5 | c6d8e4a76ba450ca70508d8a0db3a112 |
|
BLAKE2b-256 | f7af5bbd79b08c0674ba570798f98edb5f38dc13d59060f899b70f599dc4afac |
File details
Details for the file flask_file_explorer-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: flask_file_explorer-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a46eaaca0c4a8af92a4455b4f5b26367ef395d2f966927899b48cdc72060d609 |
|
MD5 | f190f1a3bafc8e99fe5f7535b45364f4 |
|
BLAKE2b-256 | 2e7db9a1e4d7b687e42a706c85168974a3eb889e3aa110d9695e0f6de549f323 |