1+ =============
12django-s3file
23=============
34
@@ -11,19 +12,23 @@ limit.
1112
1213|PyPi Version | |Build Status | |Test Coverage | |GitHub license |
1314
15+ --------
1416Features
1517--------
1618
1719- lightweight: less 200 lines
1820- no JavaScript or Python dependencies (no jQuery)
1921- easy integration
2022- works just like the built-in
23+ - extendable JavaScript API
2124
25+ -------------
2226For the Nerds
2327-------------
2428
2529.. image :: http-message-flow.svg
2630
31+ ------------
2732Installation
2833------------
2934
@@ -34,6 +39,8 @@ Just install S3file using ``pip``.
3439.. code :: bash
3540
3641 pip install django-s3file
42+ # or
43+ pipenv install django-s3file
3744
3845 Add the S3File app and middleware in your settings:
3946
@@ -52,6 +59,7 @@ Add the S3File app and middleware in your settings:
5259 ' ...' ,
5360 )
5461
62+ -----
5563Usage
5664-----
5765
@@ -63,7 +71,7 @@ when the ``DEFAULT_FILE_STORAGE`` setting is set to
6371``django-storages ``\ ’ ``S3Boto3Storage ``.
6472
6573Setting up the AWS S3 bucket
66- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74+ ----------------------------
6775
6876Upload folder
6977~~~~~~~~~~~~~
@@ -89,14 +97,62 @@ to your CORS policy.
8997 <CORSRule >
9098 <AllowedOrigin >*</AllowedOrigin >
9199 <AllowedMethod >POST</AllowedMethod >
92- <AllowedMethod >GET</AllowedMethod >
93100 <MaxAgeSeconds >3000</MaxAgeSeconds >
94101 <AllowedHeader >*</AllowedHeader >
95102 </CORSRule >
96103 </CORSConfiguration >
97104
105+ Progress Bar
106+ ------------
107+
108+ S3File does emit progress signals that can be used to display some kind of progress bar.
109+ Signals named `progress ` are emitted for both each individual file input as well as for
110+ the form as a whole.
111+
112+ The progress signal carries the following details:
113+
114+ .. code :: javascript
115+
116+ console .log (event .detail )
117+
118+ {
119+ progress: 0.4725307607171312 // total upload progress of either a form or single input
120+ loaded: 1048576 // total upload progress of either a form or single input
121+ total: 2219064 // total bytes to upload
122+ currentFile: File {…} // file object
123+ currentFileName: " text.txt" // file name of the file currently uploaded
124+ currentFileProgress: 0.47227834703299176 // upload progress of that file
125+ originalEvent: ProgressEvent {…} // the original XHR onprogress event
126+ }
127+
128+
129+ The following example implements a Boostrap progress bar for upload progress of an
130+ entire form.
131+
132+ .. code :: html
133+
134+ <div class =" progress" >
135+ <div class =" progress-bar" role =" progressbar" style =" width : 0% ;" aria-valuenow =" 0" aria-valuemin =" 0" aria-valuemax =" 100" >0%</div >
136+ </div >
137+
138+ .. code :: javascript
139+
140+ (function () {
141+ var form = document .getElementsByTagName (' form' )[0 ]
142+ var progressBar = document .getElementsByClassName (' progress-bar' )[0
143+
144+ form .addEventListener (' progress' , function (event ) {
145+ // event.detail.progress is a value between 0 and 1
146+ var percent = Math .round (event .detail .progress * 100 )
147+
148+ progressBar .setAttribute (' style' , ' width:' + percent + ' %' )
149+ progressBar .setAttribute (' aria-valuenow' , percent)
150+ progressBar .innerText = percent + ' %'
151+ })
152+ })()
153+
98154 Uploading multiple files
99- ~~~~~~~~~~~~~~~~~~~~~~~~
155+ ------------------------
100156
101157Django does have limited support for `uploading multiple files `_. S3File
102158fully supports this feature. The custom middleware makes ensure that
0 commit comments