Search code examples
node.jsamazon-s3xmlhttprequestcorsknox-amazon-s3-client

S3 set Access-Control-Allow-Origin header


I'm trying to upload a file on S3 using knox and node.js :

var s3req = s3.putBuffer(buffer, fileName, {
            'Access-Control-Allow-Origin': 'http://myurl.com',
            'Content-Type': mimetype,
            'Cache-Control': 'public, max-age=' + maxAge,
            'x-amz-acl': 'public-read'
        }, function (err, s3res) {
            // do something

The file is uploaded fine. However, when requesting the resource with XHR, it does not have the Access-Control-Allow-Origin header in the response so it fails.

Is it not possible to have this header set on a single resource? Do I have to set this on the whole bucket?


Solution

  • Simple answer would be - You have to put that on bucket because there is nothing like setting such thing at object level.

    Link to EditingBucketPermissions