# Django Chunk File Upload
Django Chunk File Upload is an alternative utility that helps you easily edit Django's chunked, drag and drop file uploads.
<img src="https://i.ibb.co/9y2SgmS/f-P5-Or-Gkxk0-Ynj00ct-G.webp" alt="f-P5-Or-Gkxk0-Ynj00ct-G">
Features
----------
- Multiple file uploads.
- Drag and Drop UI.
- MD5 checksum file: check, validate, handle duplicate files.
- Chunked uploads: optimizing large file transfers.
- Prevent uploading existing files with MD5 checksum.
- Easy to use any models.
- Image optimizer, resizer, auto convert to webp (supported webp, png, jpg, jpeg).
- Permissions.
Quickstart
----------
Install Django Chunk File Upload:
```shell
pip install git+https://github.com/thewebscraping/django-chunk-file-upload.git
```
Pypi:
```shell
pip install django-chunk-file-upload
```
Add it to your `settings.py`:
```python
INSTALLED_APPS = [
'django_chunk_file_upload',
]
```
Add it to your `urls.py`:
```python
from django.urls import path, include
urlpatterns = [
path("file-manager/", include("django_chunk_file_upload.urls")),
]
```
Run Demo
Demo URL: http://127.0.0.1:8000/file-manager/uploads/
```shell
cd examples
python manage.py migrate
python manage.py runserver
```
Change default config: `settings.py`
```python
DJANGO_CHUNK_FILE_UPLOAD = {
"chunk_size": 1024 * 1024 * 2, # # Custom chunk size upload (default: 2MB).
"upload_to": "uploads/%Y/%m/%d", # Custom upload folder.
"is_metadata_storage": True, # Save file metadata,
"remove_file_on_update": True,
"optimize": True,
"image_optimizer": {
"quality": 82,
"compress_level": 9,
"max_width": 1024,
"max_height": 720,
"to_webp": True, # Force convert image to webp type.
"remove_origin": True, # Force to delete original image after optimization.
},
"permission_classes": ("django_chunk_file_upload.permissions.AllowAny",), # default: IsAuthenticated
# "js": (
# "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
# "https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.2/spark-md5.min.js",
# "https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js",
# ), # custom js, use cdn.
# "css": ("custom.css",), # custom your css path.
}
```
Custom Your Models
----------
models.py
```python
from django.db import models
from django_chunk_file_upload.models import FileManagerMixin
class Tag(models.Model):
name = models.CharField(max_length=255)
class YourModel(FileManagerMixin):
tags = models.ManyToManyField(Tag)
custom_field = models.CharField(max_length=255)
```
forms.py
```python
from django_chunk_file_upload.forms import ChunkedUploadFileForm
from .models import YourModel
class YourForm(ChunkedUploadFileForm):
class Meta:
model = YourModel
fields = "__all__"
```
views.py
Accepted methods: GET, POST, DELETE (UPDATE, PUT does not work with FormData).
```python
from django_chunk_file_upload.views import ChunkedUploadView
from django_chunk_file_upload.typed import File
from django_chunk_file_upload.permissions import IsAuthenticated
from .forms import YourForm
class CustomChunkedUploadView(ChunkedUploadView):
form_class = YourForm
permission_classes = (IsAuthenticated,)
# file_class = File # File handle class
# file_status = app_settings.status # default: PENDING (Used when using background task, you can change it to COMPLETED.)
# optimize = True # default: True
# remove_file_on_update = True # Update image on admin page.
# chunk_size = 1024 * 1024 * 2 # Custom chunk size upload (default: 2MB).
# upload_to = "custom_folder/%Y/%m/%d" # Custom upload folder.
# template_name = "custom_template.html" # Custom template
# # Run background task like celery when upload is complete
# def background_task(self, instance):
# pass
```
custom_template.html
```html
<form action="."
method="post"
id="chunk-upload-form">
{{ form.media }}
{{ form }}
</form>
```
urls.py
```pyhon
from django.urls import path
from .views import CustomChunkedUploadView
urlpatterns = [
path("uploads/", CustomChunkedUploadView.as_view(), name="custom-uploads"),
]
```
### Permissions
```python
from django_chunk_file_upload.permissions import AllowAny, IsAuthenticated, IsAdminUser, IsSuperUser
```
### File Handlers
```python
from django_chunk_file_upload.typed import (
ArchiveFile,
AudioFile,
BinaryFile,
DocumentFile,
File,
FontFile,
HyperTextFile,
ImageFile,
JSONFile,
MicrosoftExcelFile,
MicrosoftPowerPointFile,
MicrosoftWordFile,
SeparatedFile,
XMLFile,
)
```
### Image Optimizer
Use image Optimizer feature for other modules
```python
from django_chunk_file_upload.optimize import ImageOptimizer
from django_chunk_file_upload.app_settings import app_settings
# Image optimize method: resize, crop, delete, convert and optimize
# This method calls two other methods:
# ImageOptimizer.resize: resize image
# ImageOptimizer.crop: example get parameters from Cropperjs (https://github.com/fengyuanchen/cropperjs).
image, path = ImageOptimizer.optimize(
fp='path/image.png',
filename=None, # Rename the original file.
upload_to=None, # Upload dir.
box=None, # The crop rectangle, as a (left, upper, right, lower)-tuple to crop the image.
max_width =app_settings.image_optimizer.max_width, # Max width of the image to resize.
max_height=app_settings.image_optimizer.max_height, # Max height of the image to resize.
to_webp=True, # Force convert image to webp type.
remove_origin =app_settings.image_optimizer.remove_origin, # Force to delete original image after optimization.
)
```
### UnitTests
```shell
python runtests.py
```
Note: This package is under development, only supports create view. There are also no features related to image optimization. Use at your own risk.
Raw data
{
"_id": null,
"home_page": "https://github.com/thewebscraping/django-chunk-file-upload",
"name": "django-chunk-file-upload",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "python, django, django-chunk-file-upload, django-chunk-upload, django-chunked-upload, django-drag-and-drop-file, django-dropzone, django-file, django-file-manager, django-file-upload, drag-and-drop, drag-drop",
"author": "Tu Pham",
"author_email": "thetwofarm@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2e/99/80c1bd582af76c688f2a295844c47ba5f3446f88069314d8b335a1c327b7/django_chunk_file_upload-1.0.7.tar.gz",
"platform": null,
"description": "# Django Chunk File Upload\n\nDjango Chunk File Upload is an alternative utility that helps you easily edit Django's chunked, drag and drop file uploads.\n\n<img src=\"https://i.ibb.co/9y2SgmS/f-P5-Or-Gkxk0-Ynj00ct-G.webp\" alt=\"f-P5-Or-Gkxk0-Ynj00ct-G\">\n\nFeatures\n----------\n- Multiple file uploads.\n- Drag and Drop UI.\n- MD5 checksum file: check, validate, handle duplicate files.\n- Chunked uploads: optimizing large file transfers.\n- Prevent uploading existing files with MD5 checksum.\n- Easy to use any models.\n- Image optimizer, resizer, auto convert to webp (supported webp, png, jpg, jpeg).\n- Permissions.\n\n\nQuickstart\n----------\n\nInstall Django Chunk File Upload:\n```shell\npip install git+https://github.com/thewebscraping/django-chunk-file-upload.git\n```\n\nPypi:\n```shell\npip install django-chunk-file-upload\n```\n\nAdd it to your `settings.py`:\n\n```python\nINSTALLED_APPS = [\n 'django_chunk_file_upload',\n]\n```\n\nAdd it to your `urls.py`:\n\n\n```python\nfrom django.urls import path, include\n\nurlpatterns = [\n path(\"file-manager/\", include(\"django_chunk_file_upload.urls\")),\n]\n```\n\nRun Demo\n\nDemo URL: http://127.0.0.1:8000/file-manager/uploads/\n```shell\ncd examples\npython manage.py migrate\npython manage.py runserver\n```\n\nChange default config: `settings.py`\n\n```python\nDJANGO_CHUNK_FILE_UPLOAD = {\n \"chunk_size\": 1024 * 1024 * 2, # # Custom chunk size upload (default: 2MB).\n \"upload_to\": \"uploads/%Y/%m/%d\", # Custom upload folder.\n \"is_metadata_storage\": True, # Save file metadata,\n \"remove_file_on_update\": True,\n \"optimize\": True,\n \"image_optimizer\": {\n \"quality\": 82,\n \"compress_level\": 9,\n \"max_width\": 1024,\n \"max_height\": 720,\n \"to_webp\": True, # Force convert image to webp type.\n \"remove_origin\": True, # Force to delete original image after optimization.\n },\n \"permission_classes\": (\"django_chunk_file_upload.permissions.AllowAny\",), # default: IsAuthenticated\n # \"js\": (\n # \"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js\",\n # \"https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.2/spark-md5.min.js\",\n # \"https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js\",\n # ), # custom js, use cdn.\n # \"css\": (\"custom.css\",), # custom your css path.\n}\n\n```\n\nCustom Your Models\n----------\n\nmodels.py\n\n```python\nfrom django.db import models\nfrom django_chunk_file_upload.models import FileManagerMixin\n\n\nclass Tag(models.Model):\n name = models.CharField(max_length=255)\n\n\nclass YourModel(FileManagerMixin):\n tags = models.ManyToManyField(Tag)\n custom_field = models.CharField(max_length=255)\n\n```\n\nforms.py\n\n```python\nfrom django_chunk_file_upload.forms import ChunkedUploadFileForm\nfrom .models import YourModel\n\n\nclass YourForm(ChunkedUploadFileForm):\n class Meta:\n model = YourModel\n fields = \"__all__\"\n```\n\nviews.py\n\nAccepted methods: GET, POST, DELETE (UPDATE, PUT does not work with FormData).\n```python\nfrom django_chunk_file_upload.views import ChunkedUploadView\nfrom django_chunk_file_upload.typed import File\nfrom django_chunk_file_upload.permissions import IsAuthenticated\nfrom .forms import YourForm\n\n\nclass CustomChunkedUploadView(ChunkedUploadView):\n form_class = YourForm\n permission_classes = (IsAuthenticated,)\n\n # file_class = File # File handle class\n # file_status = app_settings.status # default: PENDING (Used when using background task, you can change it to COMPLETED.)\n # optimize = True # default: True\n # remove_file_on_update = True # Update image on admin page.\n # chunk_size = 1024 * 1024 * 2 # Custom chunk size upload (default: 2MB).\n # upload_to = \"custom_folder/%Y/%m/%d\" # Custom upload folder.\n # template_name = \"custom_template.html\" # Custom template\n\n # # Run background task like celery when upload is complete\n # def background_task(self, instance):\n # pass\n```\n\ncustom_template.html\n```html\n<form action=\".\"\n method=\"post\"\n id=\"chunk-upload-form\">\n {{ form.media }}\n {{ form }}\n</form>\n```\n\nurls.py\n\n```pyhon\nfrom django.urls import path\n\nfrom .views import CustomChunkedUploadView\n\nurlpatterns = [\n path(\"uploads/\", CustomChunkedUploadView.as_view(), name=\"custom-uploads\"),\n]\n```\n\n### Permissions\n```python\nfrom django_chunk_file_upload.permissions import AllowAny, IsAuthenticated, IsAdminUser, IsSuperUser\n```\n\n### File Handlers\n```python\nfrom django_chunk_file_upload.typed import (\n ArchiveFile,\n AudioFile,\n BinaryFile,\n DocumentFile,\n File,\n FontFile,\n HyperTextFile,\n ImageFile,\n JSONFile,\n MicrosoftExcelFile,\n MicrosoftPowerPointFile,\n MicrosoftWordFile,\n SeparatedFile,\n XMLFile,\n)\n```\n\n### Image Optimizer\nUse image Optimizer feature for other modules\n\n```python\nfrom django_chunk_file_upload.optimize import ImageOptimizer\nfrom django_chunk_file_upload.app_settings import app_settings\n\n# Image optimize method: resize, crop, delete, convert and optimize\n# This method calls two other methods:\n# ImageOptimizer.resize: resize image\n# ImageOptimizer.crop: example get parameters from Cropperjs (https://github.com/fengyuanchen/cropperjs).\nimage, path = ImageOptimizer.optimize(\n fp='path/image.png',\n filename=None, # Rename the original file.\n upload_to=None, # Upload dir.\n box=None, # The crop rectangle, as a (left, upper, right, lower)-tuple to crop the image.\n max_width =app_settings.image_optimizer.max_width, # Max width of the image to resize.\n max_height=app_settings.image_optimizer.max_height, # Max height of the image to resize.\n to_webp=True, # Force convert image to webp type.\n remove_origin =app_settings.image_optimizer.remove_origin, # Force to delete original image after optimization.\n)\n```\n\n### UnitTests\n\n```shell\npython runtests.py\n```\n\nNote: This package is under development, only supports create view. There are also no features related to image optimization. Use at your own risk.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django Chunk File Upload is an alternative utility that helps you easily Django's chunked, drag and drop file uploads.",
"version": "1.0.7",
"project_urls": {
"Changelog": "https://github.com/thewebscraping/django-chunk-file-upload/blob/main/CHANGELOG.rst",
"Homepage": "https://github.com/thewebscraping/django-chunk-file-upload",
"Source": "https://github.com/thewebscraping/django-chunk-file-upload"
},
"split_keywords": [
"python",
" django",
" django-chunk-file-upload",
" django-chunk-upload",
" django-chunked-upload",
" django-drag-and-drop-file",
" django-dropzone",
" django-file",
" django-file-manager",
" django-file-upload",
" drag-and-drop",
" drag-drop"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "24b46f48968187fd8d1b28f14e7d3aa29a7d7dcf0ffbc5053235118930683816",
"md5": "103c7d119a264778eef4d6a6b5cac5c2",
"sha256": "c5b2ba87c99d2a16022ed742f920c556511fd94d0fb0a706f720b48a1af5cc79"
},
"downloads": -1,
"filename": "django_chunk_file_upload-1.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "103c7d119a264778eef4d6a6b5cac5c2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 99865,
"upload_time": "2024-12-12T09:49:48",
"upload_time_iso_8601": "2024-12-12T09:49:48.983132Z",
"url": "https://files.pythonhosted.org/packages/24/b4/6f48968187fd8d1b28f14e7d3aa29a7d7dcf0ffbc5053235118930683816/django_chunk_file_upload-1.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2e9980c1bd582af76c688f2a295844c47ba5f3446f88069314d8b335a1c327b7",
"md5": "f7e5de9919cd77a1f8365b14cc1efa6b",
"sha256": "297be546042cb334a1a735bbcb673c504c1bcc039845fe8e2f4cdd826080fb03"
},
"downloads": -1,
"filename": "django_chunk_file_upload-1.0.7.tar.gz",
"has_sig": false,
"md5_digest": "f7e5de9919cd77a1f8365b14cc1efa6b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 92889,
"upload_time": "2024-12-12T09:49:52",
"upload_time_iso_8601": "2024-12-12T09:49:52.385880Z",
"url": "https://files.pythonhosted.org/packages/2e/99/80c1bd582af76c688f2a295844c47ba5f3446f88069314d8b335a1c327b7/django_chunk_file_upload-1.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-12 09:49:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thewebscraping",
"github_project": "django-chunk-file-upload",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "Django",
"specs": [
[
">=",
"3.2"
]
]
},
{
"name": "pillow",
"specs": [
[
"~=",
"10.4.0"
]
]
}
],
"lcname": "django-chunk-file-upload"
}