Category Archives: AWS

Response for preflight is invalid – redirect 307

Just wanted to make a quick post about an error message (Response for preflight is invalid – redirect) that can probably confuse someone while working with Amazon S3 uploads directly from the browser.

I’d been testing uploads to Amazon S3 using Ember Plupload (a wrapper around Plupload) to a development bucket directly from the browser. I activated CORS by using this example and the S3 example in Ember Plupload page as it was required for direct uploads.

After I got everything working, I decided to create a “production” bucket and deploy my application pointing to that new bucket. Immediately I started getting this strange error in Chrome’s network tab while making the preflight request (the OPTIONS request).

Response for preflight is invalid (redirect) – 307

Essentially the response was a 307 redirect, instead of the 200 OK that I was expecting, and that was working on the development bucket.

Since uploading to the development bucket was working, it could only be some configuration or state that was wrong.

I checked and double checked the configurations and they were the same. I started googling without finding anything that helped.

I then looked really good at the response and noticed that the redirect was to a slightly different link than what I was expecting, it was redirecting me “https://mybucket.s3-eu-west-1.amazonaws.com” instead of the original url which was “https://mybucket.s3.amazonaws.com”.

I tried changing the upload url to this “redirect” and it started working, I checked the responses for the development bucket, and there was no mention of the “s3-west-1” anywhere.

The reason his happens (and also the reason why it self-resolves), is that when you set up an S3 bucket, there’s a certain time during which the global bucket URL is not available, so AWS redirects to the region-specific URL.

The redirect response that Amazon sends back when you request the global URL doesn’t have CORS headers, so requests will fail until the DNS has propagated.

Which has a reference to S3’s documentation:

From the documentation:

Temporary redirects automatically redirect users who do not have DNS information for the requested bucket. This occurs because DNS changes take time to propagate through the Internet. For example, if a user creates a bucket with a location constraint and immediately stores an object in the bucket, information about the bucket might not yet have been distributed throughout the Internet. Because the bucket is a subdomain of s3.amazonaws.com, Amazon S3 redirects it to the correct Amazon S3 location.

So, I basically only had to wait until Amazon propagated DNS information (took about 2 hours or so, I think). But since it didn’t happen with the development bucket (which I created before I started developing…. so, it makes sense) I got lost there.

Well, I hope that this might spare you some headaches…. just wait a bit 🙂