Response for preflight is invalid – redirect 307
Hi there!
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.
After that I found this comment on github:
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 🙂
Happy coding!
Your post saved a lot of time and effort for me, Thank you.
You’re welcome 🙂
spasibo, thank you very much for these few hours
Great to know that it helped you 🙂
Glad you posted it. thanks a lot 🙂
love you 😉
Glad I could help Stefano!
Thanks man its really helped me a lot.
For me it ended up being that the form action was set to //: instead of explicitly saying https. Testing on a local http:// vagrant box so S3 was not happy. Once I explicitly made the form action https:// it worked fine!
Hi Tom, thanks for sharing that. More troubleshooting info is always welcome. Cheers 🙂
when using boto3, you have to set addressing_style to `path` and provide region:
S3_REGION = os.environ.get(‘S3_REGION’)
s3 = boto3.client(‘s3’,S3_REGION, config=Config(s3={‘addressing_style’: ‘path’}))
http://boto3.readthedocs.io/en/latest/guide/s3.html#generating-presigned-posts
Thanks for sharing so0k!
Thank you. I’ve got the same problem, and still waiting the correction like you said 🙂
Hey Gagoit, glad I could help! Best regards.
Thanks for your post, I was tearing my hair out – also had it working on a prod site then made a dev site to test some things and had same error…
Hi Jared! Glad I could help you keep your hair 🙂 I totally understand the feeling.
Thanks, its very helpfull
Cool 🙂
Thanks for sharing. My google found your result right away no doubt saving me loads of time!
Hey Greg! Glad I could help. I did try to make the post title as close to what I googled to make it easier for people to find it.
Sensacional este post.
Me ajudou a ganhar um puta tempo, pois já estava pensando em refazer o serviço de upload revendo o que poderia estar causando o problema.
Obrigado!
Eh Tiago, ainda bem que consegui ajudar 🙂 Boa sorte com essa aplicação!
THANKS!
THANK YOU!
Hey Doug! Glad I could help! Cheers!
Thanks! same here
Thank you so much ! Spent almost 45 mins before stumbling across your post.
Cool, glad I could help! 🙂
This helped massively. Thanks 🙂
Glad I could help 🙂 Best of luck with your app!