From c3a989fcd353a1934c84f92fdea68c9c6d2684c0 Mon Sep 17 00:00:00 2001 From: Oliver de Sousa Date: Wed, 26 Jun 2019 10:38:39 +0100 Subject: [PATCH] Trimmed whitespace for AWS S3 credentials If you input a name/key to a bucket with a trailing whitespace, it will respect that trailing whitespace but will then fail to find the bucket. To resolve this, added a util function to check if it's a string. If so it will apply the `trim()` function to remove any unwanted whitespace, else it will return `undefined`. --- packages/strapi-provider-upload-aws-s3/lib/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/strapi-provider-upload-aws-s3/lib/index.js b/packages/strapi-provider-upload-aws-s3/lib/index.js index d03c0b27e1..f5f5bb1943 100644 --- a/packages/strapi-provider-upload-aws-s3/lib/index.js +++ b/packages/strapi-provider-upload-aws-s3/lib/index.js @@ -10,6 +10,8 @@ const _ = require('lodash'); const AWS = require('aws-sdk'); +const trimParam = str => typeof str === "string" ? str.trim() : undefined + module.exports = { provider: 'aws-s3', name: 'Amazon Web Service S3', @@ -55,15 +57,15 @@ module.exports = { init: (config) => { // configure AWS S3 bucket connection AWS.config.update({ - accessKeyId: config.public, - secretAccessKey: config.private, + accessKeyId: trimParam(config.public), + secretAccessKey: trimParam(config.private), region: config.region }); const S3 = new AWS.S3({ apiVersion: '2006-03-01', params: { - Bucket: config.bucket + Bucket: trimParam(config.bucket) } });