Browse Source

docs: xhrupload + tus docs

Renée Kooi 7 years ago
parent
commit
4b9bf05f13
2 changed files with 58 additions and 5 deletions
  1. 12 5
      website/src/docs/tus.md
  2. 46 0
      website/src/docs/xhrupload.md

+ 12 - 5
website/src/docs/tus.md

@@ -1,20 +1,27 @@
 ---
 ---
 type: docs
 type: docs
 order: 8
 order: 8
-title: "Tus"
+title: "Tus10"
 permalink: docs/tus/
 permalink: docs/tus/
 ---
 ---
 
 
-Tus plugin brings [tus.io](http://tus.io) resumable file uploading to Uppy by wrapping the [tus-js-client](https://github.com/tus/tus-js-client).
-
-## Options
+The Tus10 plugin brings [tus.io](http://tus.io) resumable file uploading to Uppy by wrapping the [tus-js-client][].
 
 
 ```js
 ```js
 uppy.use(Tus10, {
 uppy.use(Tus10, {
   resume: true,
   resume: true,
-  allowPause: true,
   autoRetry: true,
   autoRetry: true,
   retryDelays: [0, 1000, 3000, 5000]
   retryDelays: [0, 1000, 3000, 5000]
 })
 })
 ```
 ```
 
 
+## Options
+
+The Tus10 plugin supports all of [tus-js-client][]'s options.
+Additionally:
+
+### `autoRetry: true`
+
+Whether to auto-retry the upload when the user's internet connection is back online after an outage.
+
+[tus-js-client]: https://github.com/tus/tus-js-client

+ 46 - 0
website/src/docs/xhrupload.md

@@ -28,6 +28,7 @@ HTTP method to use for the upload.
 ### `formData: true`
 ### `formData: true`
 
 
 Whether to use a multipart form upload, using [FormData][].
 Whether to use a multipart form upload, using [FormData][].
+This works similarly to using a `<form>` element with an `<input type="file">` for uploads.
 When `true`, file metadata is also sent to the endpoint as separate form fields.
 When `true`, file metadata is also sent to the endpoint as separate form fields.
 When `false`, only the file contents are sent.
 When `false`, only the file contents are sent.
 
 
@@ -54,4 +55,49 @@ headers: {
 }
 }
 ```
 ```
 
 
+### `getResponseData(xhr)`
+
+When an upload has completed, Uppy will extract response data from the upload endpoint and send it back in the `core:upload-success` event.
+By default, Uppy assumes the endpoint will return JSON. So, if `POST /upload` responds with:
+
+```json
+{
+  "url": "https://public.url/to/file",
+  "whatever": "beep boop"
+}
+```
+
+That object will be emitted in the `core:upload-success` event.
+
+Not all endpoints respond with JSON. Providing a `getResponseData` function overrides this behavior.
+The `xhr` parameter is the `XMLHttpRequest` instance used to upload the file.
+
+For example, an endpoint that responds with an XML document:
+
+```js
+getResponseData (xhr) {
+  return {
+    url: xhr.responseXML.querySelector('Location').textContent
+  }
+}
+```
+
+### `getResponseError(xhr)`
+
+If the upload endpoint responds with a non-2xx status code, the upload is assumed to have failed.
+The endpoint might have responded with some information about the error, though.
+Pass in a `getResponseError` function to extract error data from the `XMLHttpRequest` instance used for the upload.
+
+For example, if the endpoint responds with a JSON object containing a `{ message }` property, this would show that message to the user:
+
+```js
+getResponseError (xhr) {
+  return new Error(JSON.parse(xhr.response).message)
+}
+```
+
+### `responseUrlFieldName: 'url'`
+
+The field name containing a publically accessible location of the uploaded file in the response data returned by `getResponseData(xhr)`.
+
 [FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
 [FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData