瀏覽代碼

Allow setting no ACL (#3577)

not all people use buckets with ACL

until next major you can use COMPANION_AWS_DISABLE_ACL=true
to disable setting of ACL in s3

fixes #3570
Mikael Finstad 3 年之前
父節點
當前提交
431790ee7d

+ 1 - 1
packages/@uppy/companion/src/config/companion.js

@@ -10,7 +10,7 @@ const defaultOptions = {
   },
   providerOptions: {
     s3: {
-      acl: 'public-read',
+      acl: 'public-read', // todo default to no ACL in next major
       endpoint: 'https://{service}.{region}.amazonaws.com',
       conditions: [],
       useAccelerateEndpoint: false,

+ 6 - 2
packages/@uppy/companion/src/server/Uploader.js

@@ -611,14 +611,18 @@ class Uploader {
       return chunkSize
     }
 
-    const upload = client.upload({
+    const params = {
       Bucket: options.bucket,
       Key: options.getKey(null, filename, this.options.metadata),
       ACL: options.acl,
       ContentType: this.options.metadata.type,
       Metadata: this.options.metadata,
       Body: stream,
-    }, {
+    }
+
+    if (options.acl != null) params.ACL = options.acl
+
+    const upload = client.upload(params, {
       partSize: getPartSize(this.options.chunkSize),
     })
 

+ 10 - 6
packages/@uppy/companion/src/server/controllers/s3.js

@@ -1,8 +1,8 @@
 const router = require('express').Router
 
 module.exports = function s3 (config) {
-  if (typeof config.acl !== 'string') {
-    throw new TypeError('s3: The `acl` option must be a string')
+  if (typeof config.acl !== 'string' && config.acl != null) {
+    throw new TypeError('s3: The `acl` option must be a string or null')
   }
   if (typeof config.getKey !== 'function') {
     throw new TypeError('s3: The `getKey` option must be a function')
@@ -38,12 +38,13 @@ module.exports = function s3 (config) {
     }
 
     const fields = {
-      acl: config.acl,
       key,
       success_action_status: '201',
       'content-type': req.query.type,
     }
 
+    if (config.acl != null) fields.acl = config.acl
+
     Object.keys(metadata).forEach((key) => {
       fields[`x-amz-meta-${key}`] = metadata[key]
     })
@@ -92,13 +93,16 @@ module.exports = function s3 (config) {
       return res.status(400).json({ error: 's3: content type must be a string' })
     }
 
-    client.createMultipartUpload({
+    const params = {
       Bucket: config.bucket,
       Key: key,
-      ACL: config.acl,
       ContentType: type,
       Metadata: metadata,
-    }, (err, data) => {
+    }
+
+    if (config.acl != null) params.ACL = config.acl
+
+    client.createMultipartUpload(params, (err, data) => {
       if (err) {
         next(err)
         return

+ 1 - 1
packages/@uppy/companion/src/standalone/helper.js

@@ -79,7 +79,7 @@ const getConfigFromEnv = () => {
         useAccelerateEndpoint:
           process.env.COMPANION_AWS_USE_ACCELERATE_ENDPOINT === 'true',
         expires: parseInt(process.env.COMPANION_AWS_EXPIRES || '300', 10),
-        acl: process.env.COMPANION_AWS_ACL || 'public-read',
+        acl: process.env.COMPANION_AWS_DISABLE_ACL === 'true' ? null : (process.env.COMPANION_AWS_ACL || 'public-read'), // todo default to no ACL in next major and remove COMPANION_AWS_DISABLE_ACL
       },
     },
     server: {