2

I am trying to allow access to assets from a presigned URL but I am unsure of how to do this. From this page I can see I need the following:

Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature;

Signature = Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) );

StringToSign = HTTP-Verb + "\n" +
  Content-MD5 + "\n" +
  Content-Type + "\n" +
  Date + "\n" +
  CanonicalizedAmzHeaders +
  CanonicalizedResource;

CanonicalizedResource = [ "/" + Bucket ] +
  <HTTP-Request-URI, from the protocol name up to the query string> +
  [ subresource, if present. For example "?acl", "?location", "?logging", or "?torrent"];

CanonicalizedAmzHeaders = <described below>

I know how to find the AWSAccessKeyId and the YourSecretAccessKeyID but how do I encode it using HMAC-SHA1 to form the final signature?

5
  • This pseudocode is unrelated to generating signed URLs with the Javascript SDK. Is that what you want to do? Commented Jun 14, 2017 at 2:02
  • Yes, I thought this is how you generate it Commented Jun 14, 2017 at 12:01
  • It seems you can generate it like so: s3.getSignedUrl('getObject', params, function (err, url) { console.log("The URL is", url); }); but that is to download the file, I just need to be able to display it in a browser Commented Jun 14, 2017 at 12:47
  • That will also work for displaying the file, if you uploaded it to S3 with the correct content type. Check that in the metadata of the object, in the S3 console. Commented Jun 14, 2017 at 12:52
  • What would I be looking for? Mine says "content/type application/octet-stream" and thats it Commented Jun 14, 2017 at 13:19

1 Answer 1

5

I was able to generate a presigned URL for fetching files like according to this Amazon S3 node example page:

declare var AWS:any;

AWS.config.accessKeyId = "key_goes_here";
AWS.config.secretAccessKey = "secret_key_goes_here";
AWS.config.region = "region_goes_here";

params = {
    Bucket: 'bucket_name_goes_here',
    Key:  'path_to_file_goes_here'
}

s3.getSignedUrl('getObject', params, function (err, url) { 
    // Do some sort of processing with url
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.