Browse Source

examples: make S3 endpoint configurable for aws-presigned-url

Renée Kooi 5 years ago
parent
commit
3c89563f1b
2 changed files with 12 additions and 2 deletions
  1. 8 0
      examples/aws-presigned-url/readme.md
  2. 4 2
      examples/aws-presigned-url/s3-sign.php

+ 8 - 0
examples/aws-presigned-url/readme.md

@@ -32,3 +32,11 @@ Optionally, provide a port in the `PORT` environment variable:
 ```bash
 PORT=8080 npm run example aws-presigned-url
 ```
+
+You can use a different S3-compatible service like GCS by configuring that service in `~/.aws/config` and `~/.aws/credentials`, and then providing appropriate environment variables:
+```bash
+AWS_PROFILE="gcs" \
+COMPANION_AWS_ENDPOINT="https://storage.googleapis.com" \
+COMPANION_AWS_BUCKET="test-bucket-name" \
+  npm run example aws-presigned-url
+```

+ 4 - 2
examples/aws-presigned-url/s3-sign.php

@@ -5,14 +5,16 @@ header('Access-Control-Allow-Origin: *');
 header("Access-Control-Allow-Headers: GET");
 
 // CONFIG: Change these variables to a valid region and bucket.
-$awsRegion = 'eu-west-2';
-$bucket = 'uppy-test';
+$awsEndpoint = getenv('COMPANION_AWS_ENDPOINT') ?: null;
+$awsRegion = getenv('COMPANION_AWS_REGION') ?: 'eu-west-2';
+$bucket = getenv('COMPANION_AWS_BUCKET') ?: 'uppy-test';
 // Directory to place uploaded files in.
 $directory = 'uppy-php-example';
 
 // Create the S3 client.
 $s3 = new Aws\S3\S3Client([
   'version' => 'latest',
+  'endpoint' => $awsEndpoint,
   'region' => $awsRegion,
 ]);