{"id":409,"date":"2016-01-17T19:10:36","date_gmt":"2016-01-17T19:10:36","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=409"},"modified":"2017-06-28T10:29:26","modified_gmt":"2017-06-28T10:29:26","slug":"uploading-to-amazon-s3-response-for-preflight-is-invalid-redirect-307","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2016\/01\/17\/uploading-to-amazon-s3-response-for-preflight-is-invalid-redirect-307\/","title":{"rendered":"Uploading to Amazon S3 &#8211; Response for preflight is invalid (redirect &#8211; 307)"},"content":{"rendered":"<h1>Response for preflight is invalid &#8211; redirect 307<\/h1>\n<p>Hi there!<\/p>\n<p>Just wanted to make a quick post about an error message <em>(Response for preflight is invalid &#8211; redirect)<\/em>\u00a0that can probably confuse someone while working with Amazon S3 uploads directly from the browser.<\/p>\n<p>I&#8217;d been testing uploads to Amazon S3 using <a href=\"https:\/\/github.com\/tim-evans\/ember-plupload\">Ember Plupload<\/a>\u00a0(a wrapper around <a href=\"http:\/\/www.plupload.com\">Plupload<\/a>) to\u00a0a development bucket directly from the browser.\u00a0I activated CORS by using <a href=\"http:\/\/docs.aws.amazon.com\/AmazonS3\/latest\/dev\/cors.html\">this example<\/a> and the <a href=\"https:\/\/github.com\/tim-evans\/ember-plupload#s3-direct-uploads\">S3 example<\/a> in Ember Plupload page as it was required for direct uploads.<\/p>\n<p>After I got everything working, I decided to create a &#8220;production&#8221; bucket and deploy my application pointing to that new bucket. Immediately I started getting this strange error in Chrome&#8217;s network tab while making the preflight request (the OPTIONS request).<\/p>\n<blockquote><p>Response for preflight is invalid (redirect) &#8211; 307<\/p><\/blockquote>\n<p>Essentially the response was a 307 redirect, instead of the 200 OK that I was expecting, and that was working on the development bucket.<\/p>\n<p>Since uploading to the development bucket was working, it could only be some configuration or state that was wrong.<\/p>\n<p>I checked and double checked the configurations and they were the same. I started googling without finding anything that helped.<\/p>\n<p>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 &#8220;https:\/\/mybucket.<strong>s3-eu-west-1<\/strong>.amazonaws.com&#8221; instead of the original url which was &#8220;https:\/\/mybucket.<strong>s3<\/strong>.amazonaws.com&#8221;.<\/p>\n<p>I\u00a0tried changing the upload url to this &#8220;redirect&#8221; and it started working, I checked the responses for the development bucket, and there was no mention of the &#8220;s3-west-1&#8221; anywhere.<\/p>\n<p>After that I found this <a href=\"https:\/\/github.com\/component\/s3\/issues\/7#issuecomment-45581857\">comment on github<\/a>:<\/p>\n<blockquote><p>The reason his happens (and also the reason why it self-resolves), is that when you set up an S3 bucket, there&#8217;s a certain time during which the global bucket URL is not available, so AWS redirects to the region-specific URL.<\/p>\n<p>The redirect response that Amazon sends back when you request the global URL doesn&#8217;t have CORS headers, so requests will fail until the DNS has propagated.<\/p><\/blockquote>\n<p>Which has a reference to S3&#8217;s documentation:<\/p>\n<blockquote><p>From the documentation:<\/p>\n<blockquote><p>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.<\/p><\/blockquote>\n<\/blockquote>\n<p>So, I basically only had to wait until Amazon propagated DNS information (took about 2 hours or so, I think). But since it didn&#8217;t happen with the development bucket (which I created before I started developing&#8230;. so, it makes sense) I got lost there.<\/p>\n<p>Well, I hope that this might spare you some headaches&#8230;. just wait a bit \ud83d\ude42<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Response for preflight is invalid &#8211; redirect 307 Hi there! Just wanted to make a quick post about an error message (Response for preflight is invalid &#8211; redirect)\u00a0that can probably confuse someone while working with Amazon S3 uploads directly from &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2016\/01\/17\/uploading-to-amazon-s3-response-for-preflight-is-invalid-redirect-307\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,12],"tags":[52,53],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-aws","category-web-development","tag-amazon","tag-s3"],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=409"}],"version-history":[{"count":4,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":458,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions\/458"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}