Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implemented make_link in S3 lib, signed url's

  • Loading branch information...
commit 53a386510b7a02e54dd5e5e672fb6d3d086ae2f4 1 parent 36bd0d0
Jose Luis Gordo Romero jgordor authored

Showing 1 changed file with 23 additions and 1 deletion. Show diff stats Hide diff stats

  1. +23 1 src/erlcloud_s3.erl
24 src/erlcloud_s3.erl
@@ -17,7 +17,8 @@
17 17 get_object_torrent/2, get_object_torrent/3,
18 18 get_object_metadata/2, get_object_metadata/3, get_object_metadata/4,
19 19 put_object/3, put_object/4, put_object/5, put_object/6,
20   - set_object_acl/3, set_object_acl/4]).
  20 + set_object_acl/3, set_object_acl/4,
  21 + make_link/3, make_link/4]).
21 22
22 23 -include_lib("erlcloud/include/erlcloud.hrl").
23 24 -include_lib("erlcloud/include/erlcloud_aws.hrl").
@@ -553,6 +554,27 @@ set_object_acl(BucketName, Key, ACL, Config)
553 554 XMLText = list_to_binary(xmerl:export_simple([XML], xmerl_xml)),
554 555 s3_simple_request(Config, put, BucketName, [$/|Key], "acl", [], XMLText, []).
555 556
  557 +-spec make_link(integer(), string(), string()) -> string().
  558 +
  559 +make_link(Expire_time, BucketName, Key)
  560 + when is_integer(Expire_time), is_list(BucketName), is_list(Key) ->
  561 + make_link(Expire_time, BucketName, Key, default_config()).
  562 +
  563 +-spec make_link(integer(), string(), string(), aws_config()) -> string().
  564 +
  565 +make_link(Expire_time, BucketName, Key, Config)
  566 + when is_integer(Expire_time), is_list(BucketName), is_list(Key) ->
  567 + {Mega, Sec, _Micro} = erlang:now(),
  568 + Datetime = (Mega * 1000000) + Sec,
  569 + Expires = integer_to_list(Expire_time + Datetime),
  570 + To_sign = lists:flatten(["GET\n\n\n", Expires, "\n/", BucketName, "/", Key]),
  571 + Sig = base64:encode(crypto:sha_mac(Config#aws_config.secret_access_key, To_sign)),
  572 + Host = lists:flatten(["http://", BucketName, ".", Config#aws_config.s3_host]),
  573 + URI = lists:flatten(["/", Key, "?AWSAccessKeyId=", erlcloud_http:url_encode(Config#aws_config.access_key_id), "&Signature=", erlcloud_http:url_encode(Sig), "&Expires=", Expires]),
  574 + {list_to_integer(Expires),
  575 + binary_to_list(erlang:iolist_to_binary(Host)),
  576 + binary_to_list(erlang:iolist_to_binary(URI))}.
  577 +
556 578 -spec set_bucket_attribute(string(), atom(), term()) -> ok.
557 579
558 580 set_bucket_attribute(BucketName, AttributeName, Value) ->

0 comments on commit 53a3865

Please sign in to comment.
Something went wrong with that request. Please try again.