amazon s3 - AWS S3 HTTPS API request(URL) signed with temporary security credentials to access object -


how generate https api request(url) signed temporary security credentials access aws s3 object.i able access object using amazon java sdk generate complete url temporary security credential pre signed url. package com.siriusxm.repo.test;

import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader;  import com.amazonaws.auth.basicsessioncredentials; import com.amazonaws.auth.profile.profilecredentialsprovider; import com.amazonaws.regions.region; import com.amazonaws.services.s3.amazons3client; import com.amazonaws.services.s3.model.getobjectrequest; import com.amazonaws.services.s3.model.objectlisting; import com.amazonaws.services.securitytoken.awssecuritytokenserviceclient; import com.amazonaws.services.securitytoken.model.credentials; import com.amazonaws.services.securitytoken.model.getsessiontokenrequest; import com.amazonaws.services.securitytoken.model.getsessiontokenresult; import com.siriusxm.repo.downloadserviceimpl;  public class temporarycredential {      private static string bucketname = "myrepo";      private static string key  =  "test.pdf";      public static void main(string[] args) {         system.out.println("");          awssecuritytokenserviceclient stsclient = new awssecuritytokenserviceclient(                 new profilecredentialsprovider());     //  stsclient.setregion(regionname);sts.us-west-2.amazonaws.com         //         // start session.         getsessiontokenrequest getsessiontokenrequest = new getsessiontokenrequest();         getsessiontokenresult sessiontokenresult = stsclient                 .getsessiontoken(getsessiontokenrequest);         credentials sessioncredentials = sessiontokenresult.getcredentials();         system.out.println("session credentials: "                 + sessioncredentials.tostring());         // package session credentials basicsessioncredentials         // object s3 client object use.         basicsessioncredentials basicsessioncredentials = new basicsessioncredentials(                 sessioncredentials.getaccesskeyid(),                 sessioncredentials.getsecretaccesskey(),                 sessioncredentials.getsessiontoken());          amazons3client s3object = new amazons3client(basicsessioncredentials);         // test. example, object keys given bucket.         objectlisting objects = s3object.listobjects(bucketname);         s3object.getobject( new getobjectrequest(bucketname, key));         system.out.println("no. of objects = "                 + objects.getobjectsummaries().size());     } } 

this code generate dynamically access key,secret key , security token.now need generate url authorization header signature can access s3 object directly.is there way?

from code want generate url using x-amz-security-token

if want in java, have use amazons3.generatepresignedurl

amazons3 s3client = new amazons3client(new profilecredentialsprovider());   java.util.date expiration = new java.util.date(); long msec = expiration.gettime(); msec += 1000 * 60 * 60; // 1 hour. expiration.settime(msec);  generatepresignedurlrequest generatepresignedurlrequest =                new generatepresignedurlrequest(bucketname, objectkey); generatepresignedurlrequest.setmethod(httpmethod.get); // default. generatepresignedurlrequest.setexpiration(expiration);  url s = s3client.generatepresignedurl(generatepresignedurlrequest);  

if want console, go s3 bucket, click download on object. displays box can click on "download". if right click on link , copy address link, pre-signed url object


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -