[solved] Direct to S3 fails

Trying to do an upload direct to S3. So I see in my console the flow of OPTIONS, GET, OPTION, POST and then the upload fails with Amazon returning a MethodNotAllowed on the POST

I have CORS setup to allow the domain. I am not sure what else could be the problem here?

Could you post your bucket’s CORS configuration? Does it include the permissions shown in the docs (namely, does it allow the POST method)?

<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
    <AllowedHeader>x-amz-date</AllowedHeader>
    <AllowedHeader>x-amz-content-sha256</AllowedHeader>
    <AllowedHeader>content-type</AllowedHeader>
    <AllowedHeader>content-disposition</AllowedHeader>
</CORSRule>
<CORSRule>
    <AllowedOrigin>https://myapp.herokuapp.com</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
    <AllowedHeader>x-amz-date</AllowedHeader>
    <AllowedHeader>x-amz-content-sha256</AllowedHeader>
    <AllowedHeader>content-type</AllowedHeader>
    <AllowedHeader>content-disposition</AllowedHeader>
</CORSRule>
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
</CORSRule>
</CORSConfiguration>

Ok, the CORS configuration looks good to me. Let’s check if direct upload to S3 works without Shrine. When you run the following script, does it print out a successful response?

require "aws-sdk-s3"
require "http" # gem install http

bucket = Aws::S3::Bucket.new(
  name:              "<YOUR_BUCKET>",
  region:            "<YOUR_REGION>",
  access_key_id:     "<YOUR_ACCESS_KEY_ID>",
  secret_access_key: "<YOUR_SECRET_ACCESS_KEY>",
)

presign = bucket.presigned_post(key: "foo")

response = HTTP.post presign.url, form: presign.fields.merge(
  file: HTTP::FormData::Part.new("content"),
)

p response
#<HTTP::Response/1.1 204 No Content {"X-Amz-Id-2"=>"nKftMykxP+7bfNdX41EFsQB6yJBZP9XYKAlii7/Kfu1kFYMK7YH7OYijdGeMOBXSk6/VQUHf4DY=", "X-Amz-Request-Id"=>"AFCABDDA50B114A0", "Date"=>"Thu, 23 Jan 2020 21:36:55 GMT", "Etag"=>"\"9a0364b9e99bb480dd25e1f0284c8555\"", "Location"=>"https://shrine-testing.s3.amazonaws.com/foo", "Server"=>"AmazonS3", "Connection"=>"close"}>

Yes. I got the 204 now. I had the folder in my config bucket name… removed that and then Uppy gave me back the response:

Response
body: ReadableStream { locked: false }
bodyUsed: false
headers: Headers { }
ok: true
redirected: false
status: 201
statusText: "Created"
type: "basic"
url: "[https://s3app.test/sku]

So that was good progress. But no cache or storage folders were created in my bucket, so no data was transferred to S3… next mystery…

Thanks for the help!