Ver código fonte

s3: Support fake XHR from remote uploads

Fixes https://github.com/transloadit/uppy-server/issues/71

Remote uploads via uppy-server do not have a `getResponseHeader`
function or a `responseXML` property. Instead, use the `headers` object,
and parse the XML manually.
Renée Kooi 7 anos atrás
pai
commit
42c4f29872
1 arquivos alterados com 19 adições e 4 exclusões
  1. 19 4
      src/plugins/AwsS3/index.js

+ 19 - 4
src/plugins/AwsS3/index.js

@@ -4,7 +4,7 @@ const { limitPromises } = require('../../core/Utils')
 const XHRUpload = require('../XHRUpload')
 
 function isXml (xhr) {
-  const contentType = xhr.getResponseHeader('Content-Type')
+  const contentType = xhr.headers ? xhr.headers['content-type'] : xhr.getResponseHeader('Content-Type')
   return typeof contentType === 'string' && contentType.toLowerCase() === 'application/xml'
 }
 
@@ -160,10 +160,25 @@ module.exports = class AwsS3 extends Plugin {
         if (!isXml(xhr)) {
           return { location: xhr.responseURL }
         }
-        function getValue (key) {
-          const el = xhr.responseXML.querySelector(key)
-          return el ? el.textContent : ''
+
+        let getValue = () => ''
+        if (xhr.responseXML) {
+          getValue = (key) => {
+            const el = xhr.responseXML.querySelector(key)
+            return el ? el.textContent : ''
+          }
+        }
+
+        if (xhr.responseText) {
+          getValue = (key) => {
+            const start = xhr.responseText.indexOf(`<${key}>`)
+            const end = xhr.responseText.indexOf(`</${key}>`)
+            return start !== -1 && end !== -1
+              ? xhr.responseText.slice(start + key.length + 2, end)
+              : ''
+          }
         }
+
         return {
           location: getValue('Location'),
           bucket: getValue('Bucket'),