File Sharing App
A Flask-based file sharing application with enhanced functionalities.
This Flask-based file sharing app provides a user-friendly interface for accessing files uploaded to the server. It allows users to upload, download, and view files through a web interface. Additionally, it provides an API and a CLI App for programmatic access to file management functionalities.
Features
-
User Authentication:
- Users can log in with a username and password to access the file manager's functionalities.
- Authentication is implemented for both web interface and API access.
-
File Management:
- Users can upload files through the web interface or API, with uploaded files stored in a specified upload folder on the server.
- Download and viewing functionalities are available through both the web interface and API.
-
File Listing and Sorting:
- The application provides a list of uploaded files along with their modification dates.
- Users can view the list of files sorted in ascending or descending order by modification date.
-
Last N Files Download API:
- An API endpoint allows users to download the last N uploaded files as a zip archive.
- Users can specify the number of files to include in the archive and provide a custom filename.
-
Markdown File Support:: Markdown (.md) files can be viewed directly through the web interface, rendered as plain text for easier readability.
-
PWA Offline Access:
- The application can be installed as a Progressive Web App (PWA), enabling offline access for users.
- Users can access the application even in low-connectivity environments.
-
Caching Headers:: The application sets caching headers to ensure users always access the latest content, preventing browser caching of rendered pages.
-
Enhanced CLI Integration:: Users can run the server and CLI app using the following commands:
ffs-serverorffs serverto start the server.ffs-cli <cli_command> **kwargsorffs cli <cli_command> **kwargsto run the CLI app.
-
Python Client Package:
- Users can install the Python client package with
pip install flask-file-share, enabling easy programmatic access to file management functionalities. - The package provides a client class for interacting with the API, making it simple to upload, download, and list files.
- Users can install the Python client package with
Installation and Usage
Installation
-
Install the package directly from PyPI:
pip install flask-file-share
-
Start the Flask development server:
ffs-server
-
You can instead clone the repository and install the dependencies:
# Clone the repository git clone https://github.com/hermann-web/simple-file-hosting-with-flask.git # Create a virtual environment and activate it python3 -m venv env source env/bin/activate # Install the required dependencies pip install -r requirements.txt # Start the Flask development server python src/flask_file_share/app.py
-
Access the application by visiting http://localhost:5000 in your web browser.
Web Interface Usage
The main page displays a list of shared files.
-
To upload a file, click on "Upload a File" and select the file you want to share. The uploaded files will be listed on the main page for download.
-
You can rewrite the app's setings using a custom
.envfile in the folder you are running the app from. -
You can acces the interface by running one of the following commands:
ffs server,ffs-server,python src/flask_file_share/app.py
API Usage
You can access the api with the routes http://localhost:5000/api/*.
-
All available features though the we interface are also available though the api
-
You can read the cli app documentation
Python Client Usage
You can access the api features through a python script. The module flask_file_share/client accesses the api using a context manager to handle sessions
Here is a usage example:
import flask_file_share as ffs
username = "****" # put your user token here
password = "****" # put your user key here
base_url = "http://localhost:5000"
# Example usage:
input_folder = Path("examples/data")
output_folder = Path("examples/output")
output_folder.mkdir(exist_ok=True)
client = ffs.Client(username=username, password=password, base_url=base_url)
client.login()
client.upload_file(input_folder / "test_file1.txt")
client.download_file("noexistant_file", output_folder)
client.list_files()
client.upload_file(input_folder / "test_file2.txt")
client.download_file("test_file2.txt", output_folder)
client.list_files()
client.download_last_n_files(5, output_folder)
client.logout()
You can read the python client documentation
CLI Usage
-
Run the CLI app using:
ffs-cli <cli_command> **kwargs # or ffs cli <cli_command> **kwargs # or python src/flask_file_share/cli.py
-
The file flask_file_share/app.py defines a cli app that uses the python client.
-
So, Using your cli, you can also access all features available in the python binding.
-
you can read the cli app documentation
Deployment Guide
To deploy the File Sharing App, follow these steps:
-
Choose a remote server or cloud provider to host your application. Popular options include AWS, Google Cloud, and Heroku.
-
Set up an instance or virtual machine on your chosen server.
-
Connect to your remote server.
-
Install the required dependencies.
-
Modify the Flask application's configuration to use a production-ready web server.
-
Configure your domain or subdomain to point to the IP address of your remote server.
-
Set up SSL/TLS certificates for secure HTTPS communication.
-
Start the Flask application using the production-ready web server.
-
Verify that your file sharing app is accessible.
-
Monitor the deployed application for errors and performance issues.
Remember to follow best practices for securing your deployed application.
Todo
-
Extensions Handling: Improve MIME Content-type for file opening and raw file parsing. Utilize the extensions map from github/freelamb/simple_http_server to enhance the versatility of file uploads and downloads.
-
URL Whitelisting: Implement URL whitelisting feature to restrict access to specific URLs, enhancing security.
-
Environment Variable Configuration: Allow users to set server URLs, domain, and port in the
.envfile for easier configuration management. -
CLI Integration with .env File: Enhance the CLI app to read configuration settings from the
.envfile, providing more flexibility and ease of use. -
Server Configuration Override: Provide an option for users to override server configuration settings from the CLI without relying on the
.envfile.
Contributors
- Hermann AGOSSOU
License
This project is licensed under the MIT License.
Links
- Repository: https://github.com/hermann-web/simple-file-hosting-with-flask
- Issue tracker: https://github.com/hermann-web/simple-file-hosting-with-flask/issues
- Inspiration and references:
- Flask Web framework for Python.
- Flask PWA demo
Contact
For any inquiries or issues, please contact this mail address.
Metadata
Release files for flask-file-share 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask_file_share-0.1.2.tar.gz | 9.1 MB | Without provenance | Details for flask_file_share-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_file_share-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for flask_file_share-0.1.2-py3-none-any.whl |
Total release size: 18.3 MB
Security for flask-file-share 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.