Skip to content

Commit 8c2eba8

Browse files
committed
Merge branch 'master' of github.com:lian-yue/vue-upload-component
2 parents 5a7201e + 2d94656 commit 8c2eba8

File tree

2 files changed

+132
-2
lines changed

2 files changed

+132
-2
lines changed

docs/docs/en.md

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,36 @@ This process is divided in three phases: <strong>start</strong>, <strong>upload<
139139

140140
#### start
141141

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`.
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`, `name` and `mime_type`.
143143

144144
Use the option `startBody` to add more parameters to the body of this request.
145145

146146
The backend should provide a `session_id` (to identify the upload) and a `end_offset` which is the size of every chunk
147147

148+
##### HTTP start phase example
149+
150+
Request body example:
151+
```
152+
{
153+
"phase": "start",
154+
"mime_type": "image/png",
155+
"size": 12669430,
156+
"name":"hubbleimage1stscihp1809af6400x4800.png"
157+
}
158+
```
159+
160+
Response body example:
161+
```
162+
{
163+
  "data": {
164+
    "end_offset": 6291456,
165+
    "session_id": "61db8102-fca6-44ae-81e2-a499d438e7a5"
166+
  },
167+
  "status": "success"
168+
}
169+
170+
```
171+
148172
#### upload
149173

150174
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.
@@ -153,12 +177,118 @@ We'll send the `session_id`, `start_offset` and `chunk` (the sliced blob - part
153177

154178
Use the option `uploadBody` to add more parameters to the body of this request.
155179

180+
##### HTTP upload phase example with 3 chunks
181+
182+
Request body example - chunk 1 from 3:
183+
```
184+
------WebKitFormBoundaryuI0uiY8h7MCbcysx
185+
Content-Disposition: form-data; name="phase"
186+
187+
upload
188+
------WebKitFormBoundaryuI0uiY8h7MCbcysx
189+
Content-Disposition: form-data; name="session_id"
190+
191+
61db8102-fca6-44ae-81e2-a499d438e7a5
192+
------WebKitFormBoundaryuI0uiY8h7MCbcysx
193+
Content-Disposition: form-data; name="start_offset"
194+
195+
0
196+
------WebKitFormBoundaryuI0uiY8h7MCbcysx
197+
Content-Disposition: form-data; name="chunk"; filename="blob"
198+
Content-Type: application/octet-stream
199+
200+
201+
------WebKitFormBoundaryuI0uiY8h7MCbcysx--
202+
```
203+
204+
Response body example - chunk 1 from 3:
205+
```
206+
{
207+
  "status": "success"
208+
}
209+
```
210+
211+
Request body example - chunk 2 from 3:
212+
```
213+
------WebKitFormBoundary4cjBupFqrx1SrHoR
214+
Content-Disposition: form-data; name="phase"
215+
216+
upload
217+
------WebKitFormBoundary4cjBupFqrx1SrHoR
218+
Content-Disposition: form-data; name="session_id"
219+
220+
61db8102-fca6-44ae-81e2-a499d438e7a5
221+
------WebKitFormBoundary4cjBupFqrx1SrHoR
222+
Content-Disposition: form-data; name="start_offset"
223+
224+
6291456
225+
------WebKitFormBoundary4cjBupFqrx1SrHoR
226+
Content-Disposition: form-data; name="chunk"; filename="blob"
227+
Content-Type: application/octet-stream
228+
229+
230+
------WebKitFormBoundary4cjBupFqrx1SrHoR-
231+
```
232+
233+
Response body example - chunk 2 from 3:
234+
```
235+
{
236+
  "status": "success"
237+
}
238+
```
239+
240+
Request body example - chunk 3 from 3:
241+
```
242+
------WebKitFormBoundarypWxg4xnB5QBDoFys
243+
Content-Disposition: form-data; name="phase"
244+
245+
upload
246+
------WebKitFormBoundarypWxg4xnB5QBDoFys
247+
Content-Disposition: form-data; name="session_id"
248+
249+
61db8102-fca6-44ae-81e2-a499d438e7a5
250+
------WebKitFormBoundarypWxg4xnB5QBDoFys
251+
Content-Disposition: form-data; name="start_offset"
252+
253+
12582912
254+
------WebKitFormBoundarypWxg4xnB5QBDoFys
255+
Content-Disposition: form-data; name="chunk"; filename="blob"
256+
Content-Type: application/octet-stream
257+
258+
259+
------WebKitFormBoundarypWxg4xnB5QBDoFys--
260+
```
261+
262+
Response body example - chunk 1 from 3:
263+
```
264+
{
265+
  "status": "success"
266+
}
267+
```
268+
156269
#### finish
157270

158271
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.
159272

160273
Use the option `finishBody` to add more parameters to the body of this request.
161274

275+
##### HTTP finish phase example
276+
277+
Request body example:
278+
```
279+
{
280+
"phase": "finish",
281+
"session_id": "61db8102-fca6-44ae-81e2-a499d438e7a5"
282+
}
283+
```
284+
285+
Response body example:
286+
```
287+
{
288+
  "status": "success"
289+
}
290+
```
291+
162292
#### Example
163293

164294
In the following example we are going to add `Chunk Upload Functionality`. This component will use `Chunk Upload` when the size of the file is > `1MB`, it will behave as the `Simple example` when the size of the file is lower.

src/chunk/ChunkUploadHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class ChunkUploadHandler {
4545
}
4646

4747
/**
48-
* Gets the file size
48+
* Gets the file name
4949
*/
5050
get fileName () {
5151
return this.file.name

0 commit comments

Comments
 (0)