Browse Source

Add more getResponseData() information to blog post and docs

Renée Kooi 7 years ago
parent
commit
e9ab5e4e76
2 changed files with 27 additions and 5 deletions
  1. 15 2
      website/src/_posts/2018-02-0.24.md
  2. 12 3
      website/src/docs/xhrupload.md

+ 15 - 2
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 `<DashboardModal />` React component’s target prop. 
+— It’s now possible to override `<DashboardModal />` 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/).

+ 12 - 3
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>(.*?)<\/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)
 }
 ```