@@ -12,6 +12,8 @@ Features
12
12
- Chunked uploads: optimizing large file transfers.
13
13
- Prevent uploading existing files with MD5 checksum.
14
14
- Easy to use any models.
15
+ - Image optimizer, resizer, auto convert to webp (supported webp, png, jpg, jpeg).
16
+ - Permissions.
15
17
16
18
17
19
Quickstart
@@ -57,15 +59,24 @@ Change default config: `settings.py`
57
59
DJANGO_CHUNK_FILE_UPLOAD = {
58
60
" chunk_size" : 1024 * 1024 * 2 , # # custom chunk size upload (default: 2MB).
59
61
" upload_to" : " custom_folder/%Y/%m/%d " , # custom upload folder.
60
- " is_metadata_storage" : True , # save file metadata
62
+ " is_metadata_storage" : True , # save file metadata,
63
+ " remove_file_on_update" : True ,
64
+ " optimize" : True ,
61
65
" js" : (
62
66
" https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" ,
63
67
" https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.2/spark-md5.min.js" ,
64
68
" https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js" ,
65
69
), # use cdn.
66
70
" css" : (
67
71
" custom.css"
68
- ) # custom css path.
72
+ ), # custom css path.
73
+ " image_optimizer" : {
74
+ " quality" : 82 ,
75
+ " compress_level" : 9 ,
76
+ " max_width" : 1024 ,
77
+ " max_height" : 720 ,
78
+ " to_webp" : True , # focus convert image to webp type.
79
+ }
69
80
}
70
81
71
82
```
@@ -107,11 +118,17 @@ views.py
107
118
108
119
``` python
109
120
from django_chunk_file_upload.views import ChunkedUploadView
121
+ from django_chunk_file_upload.typed import File
122
+ from django_chunk_file_upload.permissions import IsAuthenticated
110
123
from .forms import YourForm
111
124
112
125
113
126
class CustomChunkedUploadView (ChunkedUploadView ):
114
127
form_class = YourForm
128
+ permission_classes = (IsAuthenticated,)
129
+ # file_class = File # file class
130
+ # optimize = True # default: True
131
+ # remove_file_on_update = True # update image on admin page.
115
132
# chunk_size = 1024 * 1024 * 2 # custom chunk size upload (default: 2MB).
116
133
# upload_to = "custom_folder/%Y/%m/%d" # custom upload folder.
117
134
# template_name = "custom_template.html" # custom template
@@ -139,4 +156,29 @@ urlpatterns = [
139
156
]
140
157
```
141
158
159
+ ### Permissions
160
+ ``` python
161
+ from django_chunk_file_upload.permissions import AllowAny, IsAuthenticated, IsAdminUser, IsSuperUser
162
+ ```
163
+
164
+ ### File Handlers
165
+ ``` python
166
+ from django_chunk_file_upload.typed import (
167
+ ArchiveFile,
168
+ AudioFile,
169
+ BinaryFile,
170
+ DocumentFile,
171
+ File,
172
+ FontFile,
173
+ HyperTextFile,
174
+ ImageFile,
175
+ JSONFile,
176
+ MicrosoftExcelFile,
177
+ MicrosoftPowerPointFile,
178
+ MicrosoftWordFile,
179
+ SeparatedFile,
180
+ XMLFile,
181
+ )
182
+ ```
183
+
142
184
This package is under development, only supports create view. There are also no features related to image optimization. Use at your own risk.
0 commit comments