How to determine the Cache-Control header on an S3 object through a signed URL?

Following the instructions in this guide , I was able to get downloads that work through signed URLs. It looks something like this:

const s3 = new aws.S3();

const s3Params = {
  Bucket: S3_BUCKET,
  Key: fileName,
  Expires: 60,
  ContentType: fileType,
  ACL: 'public-read',
  CacheControl: 'public, max-age=31536000',
};

s3.getSignedUrl('putObject', s3Params, (err, data) => {
  // ...
});

... other than my parameter CacheControl(which I added myself, it is not in the manual) does not seem to take effect. When I use the above code to create a signed URL and upload anything to it, the resulting object in S3 is served without a header Cache-Control.

What am I doing wrong?

+6
source share
1 answer

Cache-Control , , URL-.

, . Cache-Control, , URL-, - , .. CacheControl getSignedUrl(), Cache-Control , .

Cache-Control, getSignedUrl() .

AWS , AWS Signature version 4, , , , .

JavaScript SDK : createPresignedPost().

, POST , AWS.

, http upload <form>, /, HTTP-.

( AWS, ) , POST:

{ "expiration": "2015-12-30T12:00:00.000Z",
  "conditions": [
    {"bucket": "sigv4examplebucket"},
    ["starts-with", "$key", "user/user1/"],
    {"acl": "public-read"},
    {"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"},
    ["starts-with", "$Content-Type", "image/"],
    {"x-amz-meta-uuid": "14365123651274"},
    {"x-amz-server-side-encryption": "AES256"},
    ["starts-with", "$x-amz-meta-tag", ""],

    {"x-amz-credential": "AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request"},
    {"x-amz-algorithm": "AWS4-HMAC-SHA256"},
    {"x-amz-date": "20151229T000000Z" }
  ]
}

POST :

  • UTC 30 2015 .
  • sigv4examplebucket. , (x-amz-credential ), .
  • , user/user1. , user/user1/MyPhoto.jpg.
  • ACL public-read.
  • , http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html.
  • .
  • x-amz-meta-uuid 14365123651274.
  • x-amz-meta-tag .

, CacheControl . . POST , .

+7

Source: https://habr.com/ru/post/1016660/


All Articles