{"action":"closed","issue":{"url":"https://api.github.com/repos/danialfarid/ng-file-upload/issues/1182","labels_url":"https://api.github.com/repos/danialfarid/ng-file-upload/issues/1182/labels{/name}","comments_url":"https://api.github.com/repos/danialfarid/ng-file-upload/issues/1182/comments","events_url":"https://api.github.com/repos/danialfarid/ng-file-upload/issues/1182/events","html_url":"https://github.com/danialfarid/ng-file-upload/issues/1182","id":120654109,"number":1182,"title":"s3 upload issue ","user":{"login":"Nick-t-go","id":9603047,"avatar_url":"https://avatars.githubusercontent.com/u/9603047?v=3","gravatar_id":"","url":"https://api.github.com/users/Nick-t-go","html_url":"https://github.com/Nick-t-go","followers_url":"https://api.github.com/users/Nick-t-go/followers","following_url":"https://api.github.com/users/Nick-t-go/following{/other_user}","gists_url":"https://api.github.com/users/Nick-t-go/gists{/gist_id}","starred_url":"https://api.github.com/users/Nick-t-go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nick-t-go/subscriptions","organizations_url":"https://api.github.com/users/Nick-t-go/orgs","repos_url":"https://api.github.com/users/Nick-t-go/repos","events_url":"https://api.github.com/users/Nick-t-go/events{/privacy}","received_events_url":"https://api.github.com/users/Nick-t-go/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-06T19:32:40Z","updated_at":"2015-12-06T20:04:12Z","closed_at":"2015-12-06T20:04:12Z","body":"I made minor changes to your example for uploading to s3 but I keep getting this error message:\r\n\r\n```XMLHttpRequest cannot load https://(mybucketname).s3-us-west-2.amazonaws.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1337' is therefore not allowed access.```\r\n\r\nI am not sure where the problem is coming from as this is my first time trying to upload to AWS s3. Any idea what changes I need to make to get this to work?\r\n\r\nCTRL:\r\n```\r\napp.controller('uploadCtrl', function($scope, Upload, Session, $http) {\r\n\r\n    $scope.upload = function (file) {\r\n        if (file) {\r\n            var filename = file.name;\r\n            var type = file.type;\r\n            var query = {\r\n                filename: filename,\r\n                type: type\r\n            };\r\n            $http.post('/api/upload', query)\r\n                .success(function(result) {\r\n                    Upload.upload({\r\n                        url: result.url, //s3Url\r\n                        transformRequest: function(data, headersGetter) {\r\n                            var headers = headersGetter();\r\n                            delete headers.Authorization;\r\n                            return data;\r\n                        },\r\n                        fields: result.fields, //credentials\r\n                        method: 'POST',\r\n                        file: file\r\n                    }).progress(function(evt) {\r\n                        console.log('progress: ' + parseInt(100.0 * evt.loaded / evt.total));\r\n                    }).success(function(data, status, headers, config) {\r\n                        // file is uploaded successfully\r\n                        console.log('file ' + config.file.name + 'is uploaded successfully. Response: ' + data);\r\n                    }).error(function() {\r\n\r\n                    });\r\n                })\r\n                .error(function(data, status, headers, config) {\r\n                    // called asynchronously if an error occurs\r\n                    // or server returns response with an error status.\r\n                });\r\n        }\r\n    };\r\n```\r\nrouter:\r\n```\r\nvar aws = require('./aws.config');\r\nvar crypto = require('crypto');\r\nvar moment = require('moment');\r\nvar express = require('express');\r\nvar router = express.Router();\r\n\r\nvar s3Url = 'https://' + aws.bucket + '.s3-' + aws.region + '.amazonaws.com';\r\n\r\nrouter.route('/')\r\n    .post (function(req, res) {\r\n    var request = req.body;\r\n    var fileName = request.filename;\r\n    var path = fileName;\r\n\r\n    var readType = 'private';\r\n\r\n    var expiration = moment().add(5, 'm').toDate(); //15 minutes\r\n\r\n    var s3Policy = {\r\n        'expiration': expiration,\r\n        'conditions': [{\r\n            'bucket': aws.bucket\r\n        },\r\n            ['starts-with', '$key', path],\r\n            {\r\n                'acl': readType\r\n            },\r\n            {\r\n                'success_action_status': '201'\r\n            },\r\n            ['starts-with', '$Content-Type', request.type],\r\n            ['content-length-range', 2048, 10485760], //min and max\r\n        ]\r\n    };\r\n\r\n    var stringPolicy = JSON.stringify(s3Policy);\r\n    var base64Policy = new Buffer(stringPolicy, 'utf-8').toString('base64');\r\n\r\n    // sign policy\r\n    var signature = crypto.createHmac('sha1', aws.aws_secret_access_key)\r\n        .update(new Buffer(base64Policy, 'utf-8')).digest('base64');\r\n\r\n    var credentials = {\r\n        url: s3Url,\r\n        fields: {\r\n            key: path,\r\n            AWSAccessKeyId: aws.aws_access_key_id,\r\n            acl: readType,\r\n            policy: base64Policy,\r\n            signature: signature,\r\n            'Content-Type': request.type,\r\n            success_action_status: 201\r\n        }\r\n    };\r\n    res.jsonp(credentials);\r\n});\r\n\r\nmodule.exports = router;\r\n```"}}