Explorar el Código

website,examples: set a content-type header for S3 presigned PUT uploads

As suggested by @trumpet2012. Thanks!

Closes #1233
Renée Kooi hace 5 años
padre
commit
dfb23e58a6

+ 2 - 1
examples/aws-presigned-url/main.js

@@ -32,7 +32,8 @@ uppy.use(AwsS3, {
       return {
         method: data.method,
         url: data.url,
-        fields: data.fields
+        fields: data.fields,
+        headers: data.headers
       }
     })
   }

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

@@ -36,4 +36,9 @@ echo json_encode([
   'method' => $request->getMethod(),
   'url' => (string) $request->getUri(),
   'fields' => [],
+  // Also set the content-type header on the request, to make sure that it is the same as the one we used to generate the signature.
+  // Else, the browser picks a content-type as it sees fit.
+  'headers' => [
+    'content-type' => $contentType,
+  ],
 ]);

+ 1 - 0
website/src/docs/aws-s3.md

@@ -84,6 +84,7 @@ The `fields` field is an object with form fields to send along with the upload r
 For presigned PUT uploads, this should be left empty.
 
 The `headers` field is an object with request headers to send along with the upload request.
+When using a presigned PUT upload, it's a good idea to provide `headers['content-type']`. That will ensure that the request uses the same content-type that was used to generate the signature. Without it, the browser may decide on a different content-type instead, causing S3 to reject the upload.
 
 ### `timeout: 30 * 1000`