{"action":"created","issue":{"url":"https://api.github.com/repos/refile/refile/issues/301","labels_url":"https://api.github.com/repos/refile/refile/issues/301/labels{/name}","comments_url":"https://api.github.com/repos/refile/refile/issues/301/comments","events_url":"https://api.github.com/repos/refile/refile/issues/301/events","html_url":"https://github.com/refile/refile/issues/301","id":95586647,"number":301,"title":"Presign URL is being hit over CDN","user":{"login":"abitdodgy","id":545430,"avatar_url":"https://avatars.githubusercontent.com/u/545430?v=3","gravatar_id":"","url":"https://api.github.com/users/abitdodgy","html_url":"https://github.com/abitdodgy","followers_url":"https://api.github.com/users/abitdodgy/followers","following_url":"https://api.github.com/users/abitdodgy/following{/other_user}","gists_url":"https://api.github.com/users/abitdodgy/gists{/gist_id}","starred_url":"https://api.github.com/users/abitdodgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abitdodgy/subscriptions","organizations_url":"https://api.github.com/users/abitdodgy/orgs","repos_url":"https://api.github.com/users/abitdodgy/repos","events_url":"https://api.github.com/users/abitdodgy/events{/privacy}","received_events_url":"https://api.github.com/users/abitdodgy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-17T05:00:10Z","updated_at":"2015-07-17T11:56:23Z","closed_at":null,"body":"I'm getting a CORs error while uploading after I added a CDN.\r\n\r\n```\r\nXMLHttpRequest cannot load http://redacted.cloudfront.net/attachments/cache/presign?t=1437108378113.0. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.\r\n```\r\n\r\nRefile is sending a GET request to presign the upload straight to the CDN. Is this normal? The CloudFront response is a 307 temporary redirect to my bucket. I'm a bit stumped because everything works wonderfully well until I set the host to my CDN distro.\r\n\r\n1. I created a bucket with  `cache` and `store` folders.\r\n2. I added a CORS config\r\n\r\n    ````xml\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<CORSConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\r\n    <CORSRule>\r\n        <AllowedOrigin>*</AllowedOrigin>\r\n        <AllowedMethod>GET</AllowedMethod>\r\n        <AllowedMethod>POST</AllowedMethod>\r\n        <MaxAgeSeconds>3000</MaxAgeSeconds>\r\n        <AllowedHeader>Authorization</AllowedHeader>\r\n        <AllowedHeader>Content-Type</AllowedHeader>\r\n        <AllowedHeader>Origin</AllowedHeader>\r\n    </CORSRule>\r\n</CORSConfiguration>\r\n    ````\r\n3. I created an AWS user and added a bucket policy for this user:\r\n\r\n    ````json\r\n{\r\n\t\"Version\": \"2012-10-17\",\r\n\t\"Id\": \"\",\r\n\t\"Statement\": [\r\n\t\t{\r\n\t\t\t\"Sid\": \"\",\r\n\t\t\t\"Effect\": \"Allow\",\r\n\t\t\t\"Principal\": {\r\n\t\t\t\t\"AWS\": \"arn:aws:iam::id:user/username\"\r\n\t\t\t},\r\n\t\t\t\"Action\": \"s3:*\",\r\n\t\t\t\"Resource\": [\r\n\t\t\t\t\"arn:aws:s3:::bucket\",\r\n\t\t\t\t\"arn:aws:s3:::bucket/*\"\r\n\t\t\t]\r\n\t\t}\r\n\t]\r\n}\r\n    ````\r\n4. I've configured the refile initializer.\r\n    ````ruby\r\nrequire \"refile/s3\"\r\n\r\naws = {\r\n  access_key_id: Rails.application.secrets.AWS_KEY_ID,\r\n  secret_access_key: Rails.application.secrets.AWS_SECRET_ACCESS_KEY,\r\n  region: Rails.application.secrets.AWS_REGION,\r\n  bucket: Rails.application.secrets.AWS_BUCKET,\r\n}\r\n\r\nRefile.cache = Refile::S3.new(prefix: \"cache\", **aws)\r\nRefile.store = Refile::S3.new(prefix: \"store\", **aws)\r\n    ````\r\n\r\nAt this point everything is working well. I created a CloudFront distribution for my bucket with essentially the defaults. Once I added the distribution to refile, I started getting the error.\r\n\r\n````ruby\r\nRefile.host = Rails.application.secrets.CLOUDFRONT_DISTRUBUTION\r\n````\r\n\r\nI have a feeling I'm not setting up my CDN correctly, but I am not tampering with the defaults. Any ideas?\r\n"},"comment":{"url":"https://api.github.com/repos/refile/refile/issues/comments/122255532","html_url":"https://github.com/refile/refile/issues/301#issuecomment-122255532","issue_url":"https://api.github.com/repos/refile/refile/issues/301","id":122255532,"user":{"login":"abitdodgy","id":545430,"avatar_url":"https://avatars.githubusercontent.com/u/545430?v=3","gravatar_id":"","url":"https://api.github.com/users/abitdodgy","html_url":"https://github.com/abitdodgy","followers_url":"https://api.github.com/users/abitdodgy/followers","following_url":"https://api.github.com/users/abitdodgy/following{/other_user}","gists_url":"https://api.github.com/users/abitdodgy/gists{/gist_id}","starred_url":"https://api.github.com/users/abitdodgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abitdodgy/subscriptions","organizations_url":"https://api.github.com/users/abitdodgy/orgs","repos_url":"https://api.github.com/users/abitdodgy/repos","events_url":"https://api.github.com/users/abitdodgy/events{/privacy}","received_events_url":"https://api.github.com/users/abitdodgy/received_events","type":"User","site_admin":false},"created_at":"2015-07-17T11:56:23Z","updated_at":"2015-07-17T11:56:23Z","body":"@jnicklas Weirdly enough, despite the 404, the images still upload. When trying to request the files I get this URL that produces a 404 (I've cut off some of the characters to shorted it):\r\n\r\n```\r\n//[dist].cloudfront.net/attachments/ec9f427de977492..../store/fill/100/100/74f17f4947c27bdb.../profile_image\r\n```\r\n\r\nWhere `profile_image` is the name of the attachment field. I imaged this would be:\r\n\r\n```\r\n//[dist].cloudfront.net/store/fill/100/100/74f17f4947c27bdb.../profile_image\r\n```\r\n\r\nThis maybe a similar issue to #217. Also, PR #292 may or maybe be related here.\r\n\r\nIs there a quick/dirty way to get working? I'm also a bit worried about existing uploads, and if transitioning to a CDN now will impact those.\r\n"}}