You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Changes in FileUload to use chunk upload in some cases
* `chunk-enabled` prop added to enable chunk upload
* `chunk` prop added to modify chunk upload parameters
* `ChunkUploadHandler` class created to handler chunk upload process
* Example added to the docs
* Chunk documentation added to the docs
This package allows chunk uploads, which means you can upload a file in different parts.
137
+
138
+
This process is divided in three phases: <strong>start</strong>, <strong>upload</strong>,<strong>finish</strong></p>
139
+
140
+
#### start
141
+
142
+
This is the first phase of the process. We'll tell the backend that we are going to upload a file, with certain `size` and `mime_type`.
143
+
144
+
Use the option `startBody` to add more parameters to the body of this request.
145
+
146
+
The backend will provide a `session_id` (to identify the upload) and a `end_offset` which is the size of every chunk
147
+
148
+
#### upload
149
+
150
+
In this phase we'll upload every chunk until all of them are uploaded. This step allows some failures in the backend, and will retry up to `maxRetries` times.
151
+
152
+
We'll send the `session_id`, `start_chunk` and `chunk` (the sliced blob - part of file we are uploading). We expect the backend to return `status = 'success'`, we'll retry otherwise.
153
+
154
+
Use the option `uploadBody` to add more parameters to the body of this request.
155
+
156
+
#### finish
157
+
158
+
In this phase we tell the backend that there are no more chunks to upload, so it can wrap everything. We send the `session_id` in this phase.
159
+
160
+
Use the option `finishBody` to add more parameters to the body of this request.
161
+
162
+
#### Example
163
+
164
+
```html
165
+
<file-upload
166
+
ref="upload"
167
+
v-model="files"
168
+
post-action="/post.method"
169
+
put-action="/put.method"
170
+
171
+
chunk-enabled
172
+
:chunk="{
173
+
action: '/upload/chunk',
174
+
minSize: 1048576,
175
+
maxActive: 3,
176
+
maxRetries: 5,
177
+
178
+
// In this case our backend also needs the user id to operate
179
+
startBody: {
180
+
user_id: user.id
181
+
}
182
+
}"
183
+
184
+
@input-file="inputFile"
185
+
@input-filter="inputFilter"
186
+
>
187
+
Upload file
188
+
</file-upload>
189
+
```
190
+
191
+
#### Extending the handler
192
+
193
+
We are using the class `src/chunk/ChunkUploadHandler` class to implement this protocol. You can extend this class (or even create a different one from scratch) to implement your own way to communicat with the backend.
194
+
195
+
This class must implement a method called `upload` which **must** return a promise. This promise will be used by the `FileUpload` component to determinate whether the file was uploaded or failed.
196
+
197
+
Use the `handler` parameter to use a different Handler
@@ -290,9 +364,9 @@ The `name` attribute of the input tag
290
364
291
365
***Browser:**`> IE9`
292
366
293
-
***Details:**
367
+
***Details:**
294
368
295
-
`put-action` is not empty Please give priority to` PUT` request
369
+
`put-action` is not empty Please give priority to` PUT` request
296
370
297
371
***Usage:**
298
372
```html
@@ -324,7 +398,7 @@ Attach `header` data
324
398
325
399
### data
326
400
327
-
`POST request`: Append request `body`
401
+
`POST request`: Append request `body`
328
402
`PUT request`: Append request `query`
329
403
330
404
***Type:**`Object`
@@ -347,9 +421,9 @@ File List
347
421
348
422
***Default:**`[]`
349
423
350
-
***Details:**
424
+
***Details:**
351
425
352
-
View **[`File`](#file)** details
426
+
View **[`File`](#file)** details
353
427
> In order to prevent unpredictable errors, can not directly modify the `files`, please use [`add`](#instance-methods-add), [`update`](#instance-methods-update), [`remove`](#instance-methods-remove) method to modify
354
428
355
429
***Usage:**
@@ -365,7 +439,7 @@ File List
365
439
366
440
### accept
367
441
368
-
The `accept` attribute of the input tag, MIME type
442
+
The `accept` attribute of the input tag, MIME type
369
443
370
444
***Type:**`String`
371
445
@@ -386,14 +460,14 @@ The `accept` attribute of the input tag, MIME type
386
460
387
461
### multiple
388
462
389
-
The `multiple` attribute of the input tag
390
-
Whether to allow multiple files to be selected
463
+
The `multiple` attribute of the input tag
464
+
Whether to allow multiple files to be selected
391
465
392
466
***Type:**`Boolean`
393
467
394
468
***Default:**`false`
395
469
396
-
***Details:**
470
+
***Details:**
397
471
398
472
If it is `false` file inside only one file will be automatically deleted
399
473
@@ -406,8 +480,8 @@ Whether to allow multiple files to be selected
406
480
407
481
### directory
408
482
409
-
The `directory` attribute of the input tag
410
-
Whether it is a upload folder
483
+
The `directory` attribute of the input tag
484
+
Whether it is a upload folder
411
485
412
486
***Type:**`Boolean`
413
487
@@ -426,7 +500,7 @@ Whether it is a upload folder
426
500
427
501
### extensions
428
502
429
-
Allow upload file extensions
503
+
Allow upload file extensions
430
504
431
505
***Type:**`Array | String | RegExp`
432
506
@@ -498,7 +572,7 @@ List the maximum number of files
498
572
499
573
### thread
500
574
501
-
Also upload the number of files at the same time (number of threads)
575
+
Also upload the number of files at the same time (number of threads)
502
576
503
577
***Type:**`Number`
504
578
@@ -512,8 +586,42 @@ Also upload the number of files at the same time (number of threads)
512
586
```
513
587
514
588
589
+
### chunk-enabled
590
+
591
+
Whether chunk uploads is enabled or not
592
+
593
+
***Type:**`Boolean`
594
+
595
+
***Default:**`false`
596
+
597
+
***Usage:**
598
+
```html
599
+
<file-upload:chunk-enabled="true"></file-upload>
600
+
<file-uploadchunk-enabled></file-upload>
601
+
```
602
+
603
+
### chunk
604
+
605
+
All the options to handle chunk uploads
515
606
607
+
***Type:**`Object`
516
608
609
+
***Default:**
610
+
```js
611
+
{
612
+
headers: {
613
+
'Content-Type':'application/json'
614
+
},
615
+
action:'',
616
+
minSize:1048576,
617
+
maxActive:3,
618
+
maxRetries:5,
619
+
620
+
// This is the default Handler implemented in this package
621
+
// you can use your own handler if your protocol is different
622
+
handler: ChunkUploadDefaultHandler
623
+
}
624
+
```
517
625
518
626
### drop
519
627
@@ -527,7 +635,7 @@ Drag and drop upload
527
635
528
636
***Details:**
529
637
530
-
If set to `true`, read the parent component as a container
638
+
If set to `true`, read the parent component as a container
0 commit comments