Sfoglia il codice sorgente

S3 validate parameters: display correct error for wrong method (#2577)

Co-authored-by: Ifedapo .A. Olarewaju <ifedapoolarewaju@gmail.com>
Co-authored-by: Your Name <you@example.com>
Co-authored-by: Renée Kooi <renee@kooi.me>
Enrico Sottile 4 anni fa
parent
commit
d4e9e2ed21
1 ha cambiato i file con 9 aggiunte e 2 eliminazioni
  1. 9 2
      packages/@uppy/aws-s3/src/index.js

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

@@ -134,14 +134,21 @@ module.exports = class AwsS3 extends Plugin {
   validateParameters (file, params) {
     const valid = typeof params === 'object' && params &&
       typeof params.url === 'string' &&
-      (typeof params.fields === 'object' || params.fields == null) &&
-      (params.method == null || /^(put|post)$/i.test(params.method))
+      (typeof params.fields === 'object' || params.fields == null)
 
     if (!valid) {
       const err = new TypeError(`AwsS3: got incorrect result from 'getUploadParameters()' for file '${file.name}', expected an object '{ url, method, fields, headers }' but got '${JSON.stringify(params)}' instead.\nSee https://uppy.io/docs/aws-s3/#getUploadParameters-file for more on the expected format.`)
       console.error(err)
       throw err
     }
+
+    const methodIsValid = params.method == null || /^(put|post)$/i.test(params.method)
+
+    if (!methodIsValid) {
+      const err = new TypeError(`AwsS3: got incorrect method from 'getUploadParameters()' for file '${file.name}', expected  'put' or 'post' but got '${params.method}' instead.\nSee https://uppy.io/docs/aws-s3/#getUploadParameters-file for more on the expected format.`)
+      console.error(err)
+      throw err
+    }
   }
 
   handleUpload (fileIDs) {