Browse Source

docs/examples: Fix CORS policy in S3 docs and fix reading body in PHP example.

Renée Kooi 7 years ago
parent
commit
94d6267952
2 changed files with 11 additions and 7 deletions
  1. 4 5
      examples/aws-presigned-url/s3-sign.php
  2. 7 2
      website/src/docs/aws-s3.md

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

@@ -16,11 +16,10 @@ $s3 = new Aws\S3\S3Client([
   'region' => $awsRegion,
 ]);
 
-// Retrieve data about the file to be uploaded from the query string.
-list(
-  'filename' => $filename,
-  'content-type' => $contentType,
-) = $_GET;
+// Retrieve data about the file to be uploaded from the request body.
+$body = json_decode(file_get_contents('php://input'));
+$filename = $body->filename;
+$contentType = $body->contentType;
 
 // Prepare a PutObject command.
 $command = $s3->getCommand('putObject', [

+ 7 - 2
website/src/docs/aws-s3.md

@@ -74,12 +74,14 @@ This rule looks like:
 If uploaded files should be publically viewable, but a rule like this is not present, add it.
 
 A different `<CORSRule>` is necessary to allow uploading.
-This rule should come _before_ the existing rule, because S3 uses the first rule that matches the origin of the request.
+This rule should come _before_ the existing rule, because S3 only uses the first rule that matches the origin of the request.
 
-At minimum, the domain from which the uploads will happen must be whitelisted:
+At minimum, the domain from which the uploads will happen must be whitelisted, and the definitions from the previous rule must be added:
 
 ```xml
 <AllowedOrigin>https://my-app.com</AllowedOrigin>
+<AllowedMethod>GET</AllowedMethod>
+<MaxAgeSeconds>3000</MaxAgeSeconds>
 ```
 
 When using uppy-server, which generates a POST policy document, the following permissions must be granted:
@@ -104,7 +106,10 @@ The final configuration should look something like the below:
 <?xml version="1.0" encoding="UTF-8"?>
 <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
   <CORSRule>
+    <AllowedOrigin>https://my-app.com</AllowedOrigin>
+    <AllowedMethod>GET</AllowedMethod>
     <AllowedMethod>POST</AllowedMethod>
+    <MaxAgeSeconds>3000</MaxAgeSeconds>
     <AllowedHeader>Authorization</AllowedHeader>
     <AllowedHeader>x-amz-date</AllowedHeader>
     <AllowedHeader>x-amz-content-sha256</AllowedHeader>