From d8e93cbb28d7f49ff41a59746480cba201799128 Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Sun, 15 Apr 2018 12:29:32 -0400 Subject: [PATCH 01/32] Added a note about XHR Response Handling --- website/src/_posts/2018-02-0.24.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/_posts/2018-02-0.24.md b/website/src/_posts/2018-02-0.24.md index 91b168287..f44e8123d 100644 --- a/website/src/_posts/2018-02-0.24.md +++ b/website/src/_posts/2018-02-0.24.md @@ -49,7 +49,7 @@ We’ve also added a handy “cancel” button, which should cancel everything i ## XHR Response Handling - +When the upload completes (regardless of whether it succeeded), a `response` key gets added to the file. `file.response` contains a `status` and `data` properties. `data` is the result of `getResponseData()`. ## Powered by Uppy From e9ab5e4e7647c3748ed6459af812a4973a86c816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 16 Apr 2018 09:36:34 +0200 Subject: [PATCH 02/32] Add more getResponseData() information to blog post and docs --- website/src/_posts/2018-02-0.24.md | 17 +++++++++++++++-- website/src/docs/xhrupload.md | 15 ++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/website/src/_posts/2018-02-0.24.md b/website/src/_posts/2018-02-0.24.md index f44e8123d..12300afd6 100644 --- a/website/src/_posts/2018-02-0.24.md +++ b/website/src/_posts/2018-02-0.24.md @@ -49,7 +49,20 @@ We’ve also added a handy “cancel” button, which should cancel everything i ## XHR Response Handling -When the upload completes (regardless of whether it succeeded), a `response` key gets added to the file. `file.response` contains a `status` and `data` properties. `data` is the result of `getResponseData()`. +When the upload completes (regardless of whether it succeeded), a `response` key gets added to the file. `file.response` contains a `status` and `data` properties. `data` is the result of the `getResponseData()` option. The `getResponseData()` function's signature is now: + +```js +getResponseData (responseText, response) { } +``` + +The `responseText` is the XHR endpoint response as a string. For uploads from the user's device, `response` is the [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) object. + +When uploading files from remote providers such as Dropbox or Instagram, Uppy Server sends upload response data to the client. This is made available in the `getResponseData()` option as well. The `response` object from Uppy Server contains some properties named after their [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) counterparts: + + - `response.responseText` - the XHR endpoint response as a string; + - `response.status` - the HTTP status code; + - `response.statusText` - the HTTP status text; + - `response.headers` - an object mapping lowercase header names to their values. ## Powered by Uppy @@ -65,7 +78,7 @@ This is entirely optional of course, just set `proudlyDisplayPoweredByUppy: fals - There’s now an option `showLinkToFileUploadResult: true` to disable linking to the upload result in Dashboard UI. - We are now using the image time and date as a file name in Instagram. - URL plugin checks for http(s) protocol, and add http by default if no protocol is present. -— It’s now possible to overrid `` React component’s target prop. +— It’s now possible to override `` React component’s target prop. - Provider views now have `showFilter` and `showBreadcrumbs` options, those are off for Instagram plugin, for example. - Uppy Server to Client communication has been refactored into `Provider` and `Request` modules. Request can be used when a simple request needs to be made to Uppy Server, like in URL plugin, for example. Provider is used for more complex implementations shared between Google Drive and Instagram, for example. - We’ve added Transloadit example to the website, [check it out](https://uppy.io/examples/transloadit/). diff --git a/website/src/docs/xhrupload.md b/website/src/docs/xhrupload.md index ce083c939..4aa89ce5b 100644 --- a/website/src/docs/xhrupload.md +++ b/website/src/docs/xhrupload.md @@ -101,13 +101,22 @@ That object will be emitted in the `upload-success` event. Not all endpoints res For example, an endpoint that responds with an XML document: ```js -getResponseData (xhr.responseText, xhr) { +getResponseData (responseText, xhr) { return { - url: xhr.responseXML.querySelector('Location').textContent + url: responseText.match(/(.*?)<\/Location>/)[1] } } ``` +The `responseText` is the XHR endpoint response as a string. For uploads from the user's device, `response` is the [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) object. + +When uploading files from remote providers such as Dropbox or Instagram, Uppy Server sends upload response data to the client. This is made available in the `getResponseData()` function as well. The `response` object from Uppy Server contains some properties named after their [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) counterparts: + + - `response.responseText` - the XHR endpoint response as a string; + - `response.status` - the HTTP status code; + - `response.statusText` - the HTTP status text; + - `response.headers` - an object mapping lowercase header names to their values. + ### `getResponseError(xhr.responseText, xhr)` If the upload endpoint responds with a non-2xx status code, the upload is assumed to have failed. @@ -118,7 +127,7 @@ For example, if the endpoint responds with a JSON object containing a `{ message ```js getResponseError (responseText, xhr) { - return new Error(JSON.parse(xhr.response).message) + return new Error(JSON.parse(responseText).message) } ``` From 12cb074191e04dc213fdda8d1e852d0b26672677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 16 Apr 2018 10:02:16 +0200 Subject: [PATCH 03/32] dragdrop: Link