Browse Source

s3: More robust XML check, fixes #518

Renée Kooi 7 years ago
parent
commit
4e70e13f6a
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/plugins/AwsS3/index.js

+ 6 - 2
src/plugins/AwsS3/index.js

@@ -2,6 +2,10 @@ const Plugin = require('../../core/Plugin')
 const Translator = require('../../core/Translator')
 const Translator = require('../../core/Translator')
 const XHRUpload = require('../XHRUpload')
 const XHRUpload = require('../XHRUpload')
 
 
+function isXml (xhr) {
+  return xhr.getResponseHeader('Content-Type').toLowerCase() === 'application/xml'
+}
+
 module.exports = class AwsS3 extends Plugin {
 module.exports = class AwsS3 extends Plugin {
   constructor (uppy, opts) {
   constructor (uppy, opts) {
     super(uppy, opts)
     super(uppy, opts)
@@ -124,7 +128,7 @@ module.exports = class AwsS3 extends Plugin {
       getResponseData (xhr) {
       getResponseData (xhr) {
         // If no response, we've hopefully done a PUT request to the file
         // If no response, we've hopefully done a PUT request to the file
         // in the bucket on its full URL.
         // in the bucket on its full URL.
-        if (!xhr.responseXML) {
+        if (!isXml(xhr)) {
           return { location: xhr.responseURL }
           return { location: xhr.responseURL }
         }
         }
         function getValue (key) {
         function getValue (key) {
@@ -140,7 +144,7 @@ module.exports = class AwsS3 extends Plugin {
       },
       },
       getResponseError (xhr) {
       getResponseError (xhr) {
         // If no response, we don't have a specific error message, use the default.
         // If no response, we don't have a specific error message, use the default.
-        if (!xhr.responseXML) {
+        if (!isXml(xhr)) {
           return
           return
         }
         }
         const error = xhr.responseXML.querySelector('Error > Message')
         const error = xhr.responseXML.querySelector('Error > Message')