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
After this, interaction with Flow.js is done by listening to events:
47
-
48
-
flow.on('fileAdded', function(file, event){
49
-
console.log(file, event);
50
-
});
51
-
flow.on('fileSuccess', function(file,message){
52
-
console.log(file,message);
53
-
});
54
-
flow.on('fileError', function(file, message){
55
-
console.log(file, message);
56
-
});
57
-
48
+
```javascript
49
+
flow.on('fileAdded', function(file, event){
50
+
console.log(file, event);
51
+
});
52
+
flow.on('fileSuccess', function(file,message){
53
+
console.log(file,message);
54
+
});
55
+
flow.on('fileError', function(file, message){
56
+
console.log(file, message);
57
+
});
58
+
```
58
59
## How do I set it up with my server?
59
60
60
61
Most of the magic for Flow.js happens in the user's browser, but files still need to be reassembled from chunks on the server side. This should be a fairly simple task and can be achieved in any web framework or language, which is able to receive file uploads.
@@ -82,7 +83,8 @@ For every request, you can confirm reception in HTTP status codes (can be change
82
83
Enabling the `testChunks` option will allow uploads to be resumed after browser restarts and even across browsers (in theory you could even run the same file upload across multiple tabs or different browsers). The `POST` data requests listed are required to use Flow.js to receive data, but you can extend support by implementing a corresponding `GET` request with the same parameters:
83
84
84
85
* If this request returns a `200` HTTP code, the chunks is assumed to have been completed.
85
-
* If the request returns anything else, the chunk will be uploaded in the standard fashion.
86
+
* If request returns a permanent error status, upload is stopped.
87
+
* If request returns anything else, the chunk will be uploaded in the standard fashion.
86
88
87
89
After this is done and `testChunks` enabled, an upload can quickly catch up even after a browser restart by simply verifying already uploaded chunks that do not need to be uploaded again.
88
90
@@ -92,9 +94,9 @@ After this is done and `testChunks` enabled, an upload can quickly catch up even
92
94
#### Configuration
93
95
94
96
The object is loaded with a configuration options:
95
-
96
-
var r = new Flow({opt1:'val', ...});
97
-
97
+
```javascript
98
+
var r =newFlow({opt1:'val', ...});
99
+
```
98
100
Available configuration options are:
99
101
100
102
*`target` The target URL for the multipart POST request. This can be a string or a function. If a
@@ -112,18 +114,23 @@ function, it will be passed a FlowFile, a FlowChunk and isTest boolean (Default:
112
114
include cookies as part of the request, you need to set the `withCredentials` property to true.
113
115
(Default: `false`)
114
116
*`method` Method to use when POSTing chunks to the server (`multipart` or `octet`) (Default: `multipart`)
117
+
*`testMethod` HTTP method to use when chunks are being tested. If set to a function, it will be passed a FlowFile and a FlowChunk arguments. (Default: `GET`)
118
+
*`uploadMethod` HTTP method to use when chunks are being uploaded. If set to a function, it will be passed a FlowFile and a FlowChunk arguments. (Default: `GET`)
115
119
*`prioritizeFirstAndLastChunk` Prioritize first and last chunks of all files. This can be handy if you can determine if a file is valid for your service from only the first or last chunk. For example, photo or video meta data is usually located in the first part of a file, making it easy to test support from only the first chunk. (Default: `false`)
116
120
*`testChunks` Make a GET request to the server for each chunks to see if it already exists. If implemented on the server-side, this will allow for upload resumes even after a browser crash or even a computer restart. (Default: `true`)
117
121
*`preprocess` Optional function to process each chunk before testing & sending. Function is passed the chunk as parameter, and should call the `preprocessFinished` method on the chunk when finished. (Default: `null`)
118
122
*`generateUniqueIdentifier` Override the function that generates unique identifiers for each file. (Default: `null`)
119
-
*`maxChunkRetries` The maximum number of retries for a chunk before the upload is failed. Valid values are any positive integer and `undefined` for no limit. (Default: `undefined`)
123
+
*`maxChunkRetries` The maximum number of retries for a chunk before the upload is failed. Valid values are any positive integer and `undefined` for no limit. (Default: `0`)
120
124
*`chunkRetryInterval` The number of milliseconds to wait before retrying a chunk on a non-permanent error. Valid values are any positive integer and `undefined` for immediate retry. (Default: `undefined`)
121
125
*`progressCallbacksInterval` The time interval in milliseconds between progress reports. Set it
122
126
to 0 to handle each progress callback. (Default: `500`)
123
127
*`speedSmoothingFactor` Used for calculating average upload speed. Number from 1 to 0. Set to 1
124
128
and average upload speed wil be equal to current upload speed. For longer file uploads it is
125
129
better set this number to 0.02, because time remaining estimation will be more accurate. This
126
130
parameter must be adjusted together with `progressCallbacksInterval` parameter. (Default 0.1)
131
+
*`successStatuses` Response is success if response status is in this list (Default: `[200,201,
132
+
202]`)
133
+
*`permanentErrors` Response fails if response status is in this list (Default: `[404, 415, 500, 501]`)
127
134
128
135
129
136
#### Properties
@@ -165,21 +172,24 @@ parameter must be adjusted together with `progressCallbacksInterval` parameter.
165
172
166
173
#### Events
167
174
168
-
*`.fileSuccess(file, message)` A specific file was completed. First argument `file` is instance of `FlowFile`, second argument `message` contains server response. Response is always a string.
169
-
*`.fileProgress(file)` Uploading progressed for a specific file.
175
+
*`.fileSuccess(file, message, chunk)` A specific file was completed. First argument `file` is instance of `FlowFile`, second argument `message` contains server response. Response is always a string.
176
+
Third argument `chunk` is instance of `FlowChunk`. You can get response status by accessing xhr
177
+
object `chunk.xhr.status`.
178
+
*`.fileProgress(file, chunk)` Uploading progressed for a specific file.
170
179
*`.fileAdded(file, event)` This event is used for file validation. To reject this file return false.
171
180
This event is also called before file is added to upload queue,
172
181
this means that calling `flow.upload()` function will not start current file upload.
173
182
Optionally, you can use the browser `event` object from when the file was
174
183
added.
175
184
*`.filesAdded(array, event)` Same as fileAdded, but used for multiple file validation.
176
185
*`.filesSubmitted(array, event)` Can be used to start upload of currently added files.
177
-
*`.fileRetry(file)` Something went wrong during upload of a specific file, uploading is being retried.
178
-
*`.fileError(file, message)` An error occurred during upload of a specific file.
186
+
*`.fileRetry(file, chunk)` Something went wrong during upload of a specific file, uploading is being
187
+
retried.
188
+
*`.fileError(file, message, chunk)` An error occurred during upload of a specific file.
179
189
*`.uploadStart()` Upload has been started on the Flow object.
180
190
*`.complete()` Uploading completed.
181
191
*`.progress()` Uploading progress.
182
-
*`.error(message, file)` An error, including fileError, occurred.
192
+
*`.error(message, file, chunk)` An error, including fileError, occurred.
183
193
*`.catchAll(event, ...)` Listen to all the events listed above with the same callback function.
184
194
185
195
### FlowFile
@@ -224,28 +234,28 @@ To ensure consistency throughout the source code, keep these rules in mind as yo
0 commit comments