SmoothGlue GuC2 File Uploader: a Django app providing secure, pluggable uploads to S3, MinIO, or local storage with validation, checksums, and post-processing. Built for regulated and edge environments from the ground up.
Project description
SmoothGlue Django File Uploader
A Django app providing secure, pluggable uploads to S3, MinIO, or local storage with validation, checksums, and post-processing. Built for regulated and edge environments from the ground up.
Overview
smoothglue_file_uploader simplifies the process of handling file uploads in a Django project. The core problem it solves is abstracting the storage backend, allowing developers to switch between local development, staging, and production environments without changing application code. You can configure it once in settings.py and have your file uploads seamlessly route to the correct storage solution.
Key Features
- Multiple Storage Backends: Natively supports Local Filesystem, Amazon S3, and MinIO.
- Easy Configuration: A single settings dictionary to control all storage options.
- On-the-fly Validation: Allows custom configurations to validate files prior to them being uploaded.
- Ease of Access: Easily upload, download, delete or duplicate files in any supported files stores.
Installation
Prerequisites
- Python 3.12+
- Django 4.2+
- Django REST Framework 3.14+
Install App From PyPI Package (Official Use)
-
Before installing the package, make sure that there is a virtual environment set up inside of the Django project you want to install the app into.
-
Use pip and the following command inside the Django project:
pip install smoothglue_file_uploader
-
Update the
settings.pyfile inside that Django project to point to the new app name:INSTALLED_APPS = [ "smoothglue_file_uploader", ..., ]
-
Update the
urls.pyfile inside that Django project to point to the new app name: :urlpatterns = [ path("", include("smoothglue_file_uploader.urls")), ..., ]
-
Run the development server to confirm the project continues to work.
Examples
Usage Examples
Download
storage_provider, _ = get_storage_provider()
doc = Document.objects.get(id=instance.id)
data = storage_provider.download_document(doc.path)
Upload
storage_provider, _ = get_storage_provider()
path = "foo/bar"
storage_provider.upload_document(path, file_obj)
Delete
storage_provider, _ = get_storage_provider()
doc = Document.objects.get(id=instance.id)
storage_provider.delete_document(doc.path)
Duplicate
storage_provider, _ = get_storage_provider()
old_doc = Document.objects.get(id=instance.id)
new_uuid = str(uuid.uuid4())
new_path = f"path/{new_uuid}"
duplicate_success = storage_provider.duplicate_document(old_doc.path, new_path)
API Examples
| URL Path | HTTP Method | Description |
|---|---|---|
/ |
GET |
Lists documents. A reference_id (UUID) must be provided as a query parameter to retrieve all files associated with that ID. |
/ |
POST |
Uploads a new file. The request must be a multipart form containing a file and a reference_id. |
/<uuid:file_id>/ |
GET |
Downloads the content of the specified file as a file attachment. |
/<uuid:file_id>/ |
PATCH |
Updates the metadata (e.g., name, category) of the specified file. |
/<uuid:file_id>/ |
DELETE |
Deletes the specified file from the backend storage and the database. |
Settings Example
UPLOAD_STORAGE_PROVIDER_CONFIG = {
"minio": {
"PROVIDER_CLASS": "smoothglue.file_uploader.storage_providers.minio.MinioProvider",
"PROVIDER_CONFIG": {
"ACCESS_KEY": os.getenv("ACCESS_KEY"),
"HOST": os.getenv("HOST"),
"PORT": int(os.getenv("MINIO_PORT")),
"SECRET_KEY": os.getenv("SECRET_KEY"),
"SECURE": True if os.getenv("MINIO_PROTOCOL") == "https" else False,
"BUCKET_NAME": os.getenv("BUCKET_NAME"),
"REGION": os.getenv("REGION"),
},
},
"s3-sts-web-id": {
"PROVIDER_CLASS": "smoothglue.file_uploader.storage_providers.s3.STSWebIdentityS3Provider",
"PROVIDER_CONFIG": {
"ROLE_ARN": os.getenv("ROLE_ARN", None),
"WEB_IDENTITY_TOKEN_FILE": os.getenv("WEB_IDENTITY_TOKEN_FILE", None),
"BUCKET_NAME": os.getenv("BUCKET_NAME", None),
},
},
"local": {
"PROVIDER_CLASS": "smoothglue.file_uploader.storage_providers.local.LocalFileSystemProvider",
"PROVIDER_CONFIG": {},
},
}
SELECTED_STORAGE_PROVIDER = os.getenv("DEFAULT_STORAGE_PROVIDER")
UPLOAD_STORAGE_PROVIDER_CONFIG["default"] = UPLOAD_STORAGE_PROVIDER_CONFIG[
SELECTED_STORAGE_PROVIDER
]
Settings Overview
# This setting defines the configs for the stores of smoothglue.file_uploader.storage_providers.base.StorageProvider
# which provides an interface for interacting with some storage providers. Each storage provider may come with its own
# required settings in the PROVIDER_CONFIG.
# "default" is what all files will be uploaded to without specifying a different key
UPLOAD_STORAGE_PROVIDER_CONFIG = {
"default": {
"PROVIDER_CLASS": "smoothglue.file_uploader.storage_providers.s3.BaseS3StorageProvider",
"PROVIDER_CONFIG": {...}
},
...}
# Required keys for smoothglue.file_uploader.storage_providers.s3.BaseS3StorageProvider
"BUCKET_NAME" = "..." # S3 bucket to store uploaded files in
# Required keys for smoothglue.file_uploader.storage_providers.s3.STSS3Provider
"ROLE_ARN" = "..." # IAM role for the credentials used to access S3
"BUCKET_NAME" = "..." # S3 bucket to store uploaded files in
# Required keys for smoothglue.file_uploader.storage_providers.s3.STSWebIdentityS3Provider
"ROLE_ARN" = "..." # IAM role for the credentials used to access S3
"WEB_IDENTITY_TOKEN_FILE" = "/path/to/identity/token.file"
"BUCKET_NAME" = "..." # S3 bucket to store uploaded files in
# Required keys for smoothglue.file_uploader.storage_providers.minio.MinioProvider
"ACCESS_KEY" = "..." # Access key for minio "user"
"HOST" = "minio.example.com" # Hostname or ip address of minio server
"PORT" = "1234" # (Optional) port minio service listens on if different from default
"SECRET_KEY" = "..." # Secret key for minio "user"
"SECURE" = True # True if Minio uses SSL, false otherwise
"BUCKET_NAME" = "..." # Minio bucket to store uploaded files in
# A dictionary of file extensions to post-processor classes. These post-processor classes are ran after a file has been
# successfully uploaded to the configured storage provider
UPLOAD_POST_PROCESSORS = {
# Will be applied to EVERY file uploaded
"*": "smoothglue.file_uploader.post_processor.DefaultUploadProcessor",
# Will be applied to all files uploaded that end in `.txt`
"txt": "some.other.post.processing.class"
}
# A dictionary of file extensions to file validator classes. These file validator classes are ran before a file is
# uploaded and may raise a validation error (resulting in 400 response).
UPLOAD_VALIDATORS = {
# Will be applied to EVERY file uploaded
"*": "smoothglue.file_uploader.validators.DefaultValidator",
# Will be applied to all files uploaded that end in `.txt`
"txt": "some.other.validation.class",
}
Local File System Storage Provider
Used for running a simple upload to the file system. Defaults go to the Django MEDIA_ROOT configuration, otherwise you can specify the location using UPLOAD_PATH in the config.
UPLOAD_STORAGE_PROVIDER_CONFIG = {
"default": {
"PROVIDER_CLASS": "smoothglue.file_uploader.storage_providers.local.LocalFileSystemProvider",
"PROVIDER_CONFIG": {"UPLOAD_PATH": "/tmp/uploaded_files"}
},
...
}
Optional File Checksum validation
# calculate sha256 file checksum and inserts it to the db. May cause performance issue for large file uploads
CALCULATE_CHECKSUM: bool = True
# Enforce checksum validation if an existing file with the same checksum exist in the document table.
UPLOAD_VALIDATORS={
"*": "smoothglue.file_uploader.validators.DuplicateFileValidator"
}
License
This project is licensed under a Proprietary License. See the LICENSE file for more details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smoothglue_file_uploader-1.0.5.tar.gz.
File metadata
- Download URL: smoothglue_file_uploader-1.0.5.tar.gz
- Upload date:
- Size: 28.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/4.18.0-553.51.1.el8_10.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b332c9adc98abeb9d2535d7b8398141944537f2947487cd2722acce1c2c01dee
|
|
| MD5 |
a0f560c8b0fabf3a52d1c9fe0d50f988
|
|
| BLAKE2b-256 |
aa19daa01efcb8331375f2e01a2933ae1c4b1dab4d8fc112dbf89d2650a04707
|
File details
Details for the file smoothglue_file_uploader-1.0.5-py3-none-any.whl.
File metadata
- Download URL: smoothglue_file_uploader-1.0.5-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/4.18.0-553.51.1.el8_10.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56f94e098f69cade14daad491c3d9c1bc78fd52a4c50079f22209b315ff1c534
|
|
| MD5 |
c30ee69b6d159a6eb8a4116f743290dc
|
|
| BLAKE2b-256 |
f78691d754c959f44c544386310ab217c3cf4fa34a4cdff714d8fcc6eefea804
|