forked from SaltwaterC/aws2js
-
Notifications
You must be signed in to change notification settings - Fork 0
s3.signUrl()
SaltwaterC edited this page Jul 30, 2012
·
1 revision
Low level method for creating pre-signed URLs to be used with a standard HTTP client.
s3.signUrl(protocol, method, path, expires, headers)
- 'protocol' - a string indicating the protocol. Accepted values: 'http' or 'https'. Throws an Error otherwise.
- 'method' - a string indicating the HTTP method for the pre-signed URL. Must be one of the following: 'GET', 'HEAD', 'POST', 'PUT', or 'DELETE'. If you don't like to yell in your code, you can passed the lower cased versions such as 'get', 'head', etc. Throws an Error otherwise.
- 'expires' - a Date object indicating the expiration time. Obviously, in order to produce useful output from this function, the Date must be in the future, but I won't stop you to shoot yourself in the foot. Throws an Error if the argument is not a Date object.
- 'headers' - an object containing the HTTP headers you may want to pass to the HTTP request, such as the x-amz-* metadata headers.
This method returns a pre-signed URL that you may use with a standard HTTP client. The most common usage of this method is for generating temporary download URLs for private resources. Since there's a 'method' argument, you may use the method for any of the accepted HTTP methods by the S3 API.
var time = new Date();
time.setMinutes(time.getMinutes() + 60);
s3.setBucket('johnsmith').signUrl('https', 'GET', '/photos/puppy.jpg', time);
// => https://johnsmith.s3.amazonaws.com/photos/puppy.jpg?AWSAccessKeyId=AKIAEXAMPLE&Signature=rucSbH0etc