node.js - s3 failing on preflight even with cors all methods and origins -


i don't understand... seems simple, yet fails on options call put request. "response preflight invalid"

s3 cors:

<?xml version="1.0" encoding="utf-8"?> <corsconfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">     <corsrule>         <allowedorigin>*</allowedorigin>         <allowedmethod>get</allowedmethod>         <allowedmethod>put</allowedmethod>         <allowedmethod>post</allowedmethod>         <maxageseconds>3000</maxageseconds>         <allowedheader>*</allowedheader>     </corsrule> </corsconfiguration> 

the url:

http://localhost:9002/api/sign_s3?file_name=wcyqzgrkis24or4mv4hdpp-uxdnq6p9mvoj6drmpcju.jpg&file_type=image/jpeg 

the url s3 (keys removed):

https://jayehtest.s3.amazonaws.com/wcyqzgrkis24or4mv4hdpp-uxdnq6p9mvoj6drmpcju.jpg?awsaccesskeyid=xxx&content-type=image%2fjpeg&expires=1454923884&signature=xxx&x-amz-acl=public-read 

the code generate put:

    aws.config.update({accesskeyid: process.env.aws_access_key, secretaccesskey: process.env.aws_secret_key});     var s3 = new aws.s3();     var s3_params = {         bucket: process.env.s3_bucket,         key: req.query.file_name,         //expires: 120,         //contenttype:  req.query.file_type,         contenttype: "multipart/form-data",         acl: 'public-read-write',     };     s3.getsignedurl('putobject', s3_params, function(err, data){         console.log('got signed url!');         if(err)             res.status(500).json({error: err});         else             res.status(200).json({                 signed_request: data,                 url: 'https://'+process.env.s3_bucket+'.s3.amazonaws.com/'+req.query.file_name             });     }); 

the code make put request:

    superagent('get', '/api/sign_s3?file_name='+files[0].name+'&file_type='+files[0].type).end(function(err, response) {             console.log('signs3 response: ', response);              superagent('put', response.body.signed_request)             //superagent('put', 'https://jayehtest.s3-us-west-2.amazonaws.com/10172871_10101161917002037_713851410092755221_n.jpg?awsaccesskeyid=akiajoq7al7qgigsxmqq&content-type=image%2fjpeg&expires=1454947575&signature=nbvjbkcld5xsvfktejnqotdrfzm%3d&x-amz-acl=public-read'             .set('x-amz-acl', 'public-read-write')             .set('content-type', 'multipart/form-data')             .attach('image', files[0])             .end(cb);         }); 

there many stupid layers s3, needed few things perfect:

  1. the headers needed match exactly. content-type needed character character same.

  2. x-amz-acl , acl on node need both set @ least public-read

  3. you need generate bucket policy in s3 gives permission access_key

  4. it needs put request [but resolved quickly]

notes: created iam user, didn't use it. iam user didn't work. works fine public keys.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -