Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I add x-amz-acl:public-read to an Amazon S3 Secure Url
    primarykey
    data
    text
    <p><strong>My scenario:</strong> I need to generate a secure url to hand to a client. That client will use the url to post a file directly to S3. The file should then be available to the public.</p> <p>I am currently trying to figure out all the moving parts via unit test. I am using the <a href="https://github.com/LearnBoost/knox" rel="nofollow">knox</a> module's implementation to generate secure URLs.</p> <p>Here is my test:</p> <pre><code>'use strict'; var fs = require('fs'), knox = require('knox'), request = require('request'), config = require('../config'); var s3 = new knox.createClient({ key : config.aws.accessKey, secret : config.aws.secretKey, bucket : 'poopdart' }); exports.url_generation = { put_object: function(test) { var file = '/foo/' + new Date().valueOf() + '.json'; var qs = { 'x-amz-acl': 'public-read' }; var signedUrl = s3.signedUrl(file, new Date(new Date().getTime() + 5 * 60 * 1000), { verb: 'PUT', contentType: 'application/json' // qs: qs }); console.log(signedUrl); var body = JSON.stringify({ date: new Date() }); var options = { url: signedUrl, method: 'PUT', body: body, headers: { 'Content-Type': 'application/json', 'Content-Length': body.length, 'x-amz-acl': 'public-read' } }; request(options, function (err, response, data) { if(response.statusCode !== 200) console.log(data); test.equals(response.statusCode, 200); request.get('https://print-template-images.s3.amazonaws.com' + file, function (err, response, data) { test.equals(response.statusCode, 200); // fails with 403 test.done(); }); }); } }; </code></pre> <p><strong>Note:</strong> If i add the x-amz-acl header to my post request the key validation fails. If I add it to the querystring of the signed url it is ignored and the file is left private. </p> <p>Anyone have pointers?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload