Browse Source

Allow overriding of getResponseData() (#1647)

* Allow overriding of getResponseData()

* aws-s3: document getResponseData()
Randy Etheredge 5 years ago
parent
commit
5d895f2bfa
2 changed files with 17 additions and 2 deletions
  1. 9 2
      packages/@uppy/aws-s3/src/index.js
  2. 8 0
      website/src/docs/aws-s3.md

+ 9 - 2
packages/@uppy/aws-s3/src/index.js

@@ -171,7 +171,7 @@ module.exports = class AwsS3 extends Plugin {
     this.uppy.addPreProcessor(this.prepareUpload)
 
     let warnedSuccessActionStatus = false
-    this.uppy.use(XHRUpload, {
+    let xhrUploadOpts = {
       fieldName: 'file',
       responseUrlFieldName: 'location',
       timeout: this.opts.timeout,
@@ -227,7 +227,14 @@ module.exports = class AwsS3 extends Plugin {
         const error = getXmlValue(content, 'Message')
         return new Error(error)
       }
-    })
+    }
+
+    // Replace getResponseData() with overwritten version.
+    if (this.opts.getResponseData) {
+      xhrUploadOpts.getResponseData = this.opts.getResponseData
+    }
+
+    this.uppy.use(XHRUpload, xhrUploadOpts)
   }
 
   uninstall () {

+ 8 - 0
website/src/docs/aws-s3.md

@@ -96,6 +96,14 @@ The default is 30 seconds.
 Limit the amount of uploads going on at the same time. This is passed through to [XHRUpload](/docs/xhrupload#limit-0); see its documentation page for details.
 Set to `0` to disable limiting.
 
+### `getResponseData(responseText, response)`
+
+> This is an advanced option intended for use with _almost_ S3-compatible storage solutions.
+
+Customize response handling once an upload is completed. This passes the function through to @uppy/xhr-upload, see its [documentation](https://uppy.io/docs/xhr-upload/#getResponseData-responseText-response) for API details.
+
+This option is useful when uploading to an S3-like service that doesn't reply with an XML document, but with something else such as JSON.
+
 ### `locale: {}`
 
 Localize text that is shown to the user.