Skip to content

Instantly share code, notes, and snippets.

@x-blood
Last active October 26, 2017 00:47
Show Gist options
  • Save x-blood/8b7d66017926ca8cc6ad69dfdf5c920a to your computer and use it in GitHub Desktop.
Save x-blood/8b7d66017926ca8cc6ad69dfdf5c920a to your computer and use it in GitHub Desktop.
(AWS)EC2のWebApplicationからS3の署名付きURLを取得する方法
Date expiration = new Date();
long msec = expiration.getTime();
msec += 1000 * 60 * 60; // 1 hour.
// 有効期限の設定(デフォルトは15分らしい)
expiration.setTime(msec);
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, path);
// GET Request(POSTもできる)
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
URL url = client.generatePresignedUrl(generatePresignedUrlRequest);
return url.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment