本文整理汇总了Java中com.amazonaws.services.s3.model.GeneratePresignedUrlRequest.setExpiration方法的典型用法代码示例。如果您正苦于以下问题:Java GeneratePresignedUrlRequest.setExpiration方法的具体用法?Java GeneratePresignedUrlRequest.setExpiration怎么用?Java GeneratePresignedUrlRequest.setExpiration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.model.GeneratePresignedUrlRequest
的用法示例。
在下文中一共展示了GeneratePresignedUrlRequest.setExpiration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePreSignUrl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
/**
* Method to generate pre-signed object URL to s3 object
* @param bucketName AWS S3 bucket name
* @param key (example: android/apkFolder/ApkName.apk)
* @param ms espiration time in ms, i.e. 1 hour is 1000*60*60
* @return url String pre-signed URL
*/
public URL generatePreSignUrl(final String bucketName, final String key, long ms) {
java.util.Date expiration = new java.util.Date();
long msec = expiration.getTime();
msec += ms;
expiration.setTime(msec);
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
URL url = s3client.generatePresignedUrl(generatePresignedUrlRequest);
return url;
}
示例2: generateUrl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
@NotNull
static URL generateUrl(@NotNull final String bucketName, @NotNull final String objectKey) throws IOException {
try {
LOGGER.info("Generating pre-signed URL for bucket: {}\tobject: {}", bucketName, objectKey);
final long millisNow = System.currentTimeMillis();
final long expirationMillis = millisNow + 1000 * 60 * 120; //add 2 hours;
final Date expiration = new java.util.Date(expirationMillis);
final GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
return s3Client.generatePresignedUrl(generatePresignedUrlRequest);
} catch (AmazonServiceException exception) {
LOGGER.error("Error Message: {}", exception.getMessage());
LOGGER.error("HTTP Code: {}", exception.getStatusCode());
LOGGER.error("Error Code: {}", exception.getErrorCode());
LOGGER.error("Error Type: {}", exception.getErrorType());
LOGGER.error("Request ID: {}", exception.getRequestId());
} catch (AmazonClientException ace) {
LOGGER.error("The client encountered an internal error while trying to communicate with S3");
LOGGER.error("Error Message: {}", ace.getMessage());
}
throw new IOException("Failed to create sbp URL.");
}
示例3: getSignedUrl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
public URL getSignedUrl(String p_s3_bucket, String p_s3_file, Date p_exires) {
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(p_s3_bucket, p_s3_file);
generatePresignedUrlRequest.setMethod(HttpMethod.GET); // Default.
generatePresignedUrlRequest.setExpiration(p_exires);
return s3Client.generatePresignedUrl(generatePresignedUrlRequest);
}
示例4: generatePresignedUrl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
@Override
public URL generatePresignedUrl(String bucketName, String key, Date expiration, HttpMethod method)
throws SdkClientException {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, method);
request.setExpiration(expiration);
return generatePresignedUrl(request);
}
示例5: main
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// create the AWS S3 Client
AmazonS3 s3 = AWSS3Factory.getS3Client();
// retrieve the key value from user
System.out.println( "Enter the object key:" );
String key = new BufferedReader( new InputStreamReader( System.in ) ).readLine();
// retrieve the expiration time for the object from user
System.out.print( "How many hours should this tag be valid? " );
String hours = new BufferedReader( new InputStreamReader( System.in ) ).readLine();
// convert hours to a date
Date expiration = new Date();
long curTime_msec = expiration.getTime();
long nHours = Long.valueOf(hours);
curTime_msec += 60 * 60 * 1000 * nHours;
expiration.setTime(curTime_msec);
// generate the object's pre-signed URL
GeneratePresignedUrlRequest presignedUrl = new GeneratePresignedUrlRequest(AWSS3Factory.S3_BUCKET, key);
presignedUrl.setMethod(HttpMethod.GET);
presignedUrl.setExpiration(expiration);
URL url = s3.generatePresignedUrl(presignedUrl);
// print object's pre-signed URL
System.out.println( String.format("object [%s/%s] pre-signed URL: [%s]",
AWSS3Factory.S3_BUCKET, key, url.toString()));
}
示例6: generateGetObjectPresignedUrl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
@Override
public String generateGetObjectPresignedUrl(String bucketName, String key, Date expiration, S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto)
{
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
AmazonS3Client s3 = getAmazonS3(s3FileTransferRequestParamsDto);
try
{
return s3Operations.generatePresignedUrl(generatePresignedUrlRequest, s3).toString();
}
finally
{
s3.shutdown();
}
}
示例7: generateObjectURL
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
@Override
public URL generateObjectURL(final String bucketName, final String fileName, final Date expires)
throws AmazonClientException, AmazonServiceException {
LOGGER.info("generateObjectURL invoked, bucketName: {}, fileName: {} and expires: {}", bucketName, fileName, expires);
final GeneratePresignedUrlRequest presignedUrlReq = new GeneratePresignedUrlRequest(bucketName, fileName);
presignedUrlReq.setExpiration(expires);
return s3client.generatePresignedUrl(presignedUrlReq);
}
示例8: getDirectDownloadHandle
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
@Override
public Optional<DirectDownloadHandle> getDirectDownloadHandle(String key)
{
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, key);
req.setExpiration(Date.from(Instant.now().plusSeconds(10*60)));
String url = client.generatePresignedUrl(req).toString();
return Optional.of(DirectDownloadHandle.of(url));
}
示例9: getDirectUploadHandle
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
@Override
public Optional<DirectUploadHandle> getDirectUploadHandle(String key)
{
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, key);
req.setMethod(HttpMethod.PUT);
req.setExpiration(Date.from(Instant.now().plusSeconds(10*60)));
String url = client.generatePresignedUrl(req).toString();
return Optional.of(DirectUploadHandle.of(url));
}
示例10: buildPresignedURL
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
/**
* Computes the presigned URL for the given S3 resource.
*
* @param path String like "/bucketName/folder/folder/abc.txt" that
* represents the resource to request.
*/
public URL buildPresignedURL(String path) throws AmazonClientException {
AWSCredentials credentials = awsCredentialsProvider.getCredentials();
long expires = System.currentTimeMillis() + 60 * 60 * 1000;
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(path, credentials.getAWSSecretKey());
request.setExpiration(new Date(expires));
AmazonS3 s3 = new AmazonS3Client(credentials);
return s3.generatePresignedUrl(request);
}
示例11: execute
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
@Override
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
AmazonKey amazonKey = getAmazonKey(_session, argStruct);
AmazonS3 s3Client = getAmazonS3(amazonKey);
String bucket = getNamedStringParam(argStruct, "bucket", null );
String key = getNamedStringParam(argStruct, "key", null );
if ( bucket == null )
throwException(_session, "Please specify a bucket" );
if ( key == null )
throwException(_session, "Please specify a key" );
if ( key.charAt( 0 ) == '/' )
key = key.substring(1);
cfData expired = getNamedParam(argStruct,"expiration", null );
try {
Date expirationDate;
if ( expired != null ){
if ( expired.getDataType() == cfData.CFDATEDATA )
expirationDate = new Date( expired.getLong() );
else
expirationDate = new Date( System.currentTimeMillis() + (expired.getLong() * DateUtil.SECS_MS) );
}else{
expirationDate = new Date( System.currentTimeMillis() + DateUtil.DAY_MS*7 );
}
GeneratePresignedUrlRequest g = new GeneratePresignedUrlRequest(bucket, key);
g.setExpiration(expirationDate);
return new cfStringData( s3Client.generatePresignedUrl(g).toString() );
} catch (Exception e) {
throwException(_session, "AmazonS3: " + e.getMessage() );
return cfBooleanData.FALSE;
}
}
示例12: put
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
public static URL put(String key, File movie){
try{
System.out.println("Uploading a new object to S3 from a file\n");
s3.putObject(new PutObjectRequest(bucketName, key, movie));
System.out.println("Generating pre-signed URL.");
java.util.Date expiration = new java.util.Date();
long milliSeconds = expiration.getTime();
milliSeconds += 1000 * 60 * 60 * 24 * 7; // Add 7 days.
expiration.setTime(milliSeconds);
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
return s3.generatePresignedUrl(generatePresignedUrlRequest);
}catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which means your request made it "
+ "to Amazon S3, but was rejected with an error response for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with S3, "
+ "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}
return null;
}
示例13: makeConfigFileURL
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
public static final String makeConfigFileURL(String configUrl) throws Exception {
String url = null;
if (configUrl.startsWith("http")) {
url = configUrl;
} else if (configUrl.startsWith("s3")) {
AmazonS3 s3Client = new AmazonS3Client();
String bucket = configUrl.split("/")[2];
String prefix = configUrl.substring(configUrl.indexOf(bucket) + bucket.length() + 1);
// generate a presigned url for X hours
Date expiration = new Date();
long msec = expiration.getTime();
msec += 1000 * 60 * 60; // 1 hour.
expiration.setTime(msec);
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(
bucket, prefix);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
URL s3url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
url = s3url.toString();
} else {
url = new URL(String.format("file://%s", configUrl)).toString();
}
return url;
}
示例14: generate
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
protected WorkOrderResult generate(AmazonS3 s3Conn, AuthLinkSpec spec, Date ttl) {
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(spec.getTarget().getBucketName(), spec.getTarget().getObjectName());
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(ttl);
URL url =null;
WorkOrderResult woResult=new WorkOrderResult(spec);
// If WorkOrder contains an https request, generate that
if(spec.getProtocol().isHttps()) {
// Set HTTPS protocol URL by accessing the s3 https endpoint
s3Conn.setEndpoint(HTTPS_ENDPOINT_);
url = s3Conn.generatePresignedUrl(generatePresignedUrlRequest);
woResult.getSignedHttpsUrl().setUrl(url.toString());
//woResult.getSignedHttpsUrl().setProtocol(HTTPS_);
if(spec.getProcessing().isValidateAuthURL() == true) {
if(validTarget(url)) {
woResult.getSignedHttpsUrl().setValid(true);
}
}
}
// If WorkOrder contains an http request, generate that
if(spec.getProtocol().isHttp()) {
// Set HTTP protocol URL by accessing the s3 http endpoint
s3Conn.setEndpoint(HTTP_ENDPOINT_);
url = s3Conn.generatePresignedUrl(generatePresignedUrlRequest);
woResult.getSignedHttpUrl().setUrl(url.toString());
//woResult.getSignedHttpUrl().setProtocol(HTTP_);
if(spec.getProcessing().isValidateAuthURL() == true) {
if(validTarget(url)) {
woResult.getSignedHttpUrl().setValid(true);
}
}
}
return(woResult);
}
示例15: setACLurl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入方法依赖的package包/类
String setACLurl(String object, String access_key, String secret_key, String endpoint, String bucket) {
String URL = null;
try {
AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
AmazonS3 s3Client = new AmazonS3Client(credentials,
new ClientConfiguration());
if (endpoint.contains("amazonaws.com")) {
String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket));
if (aws_endpoint.contains("US")) {
s3Client.setEndpoint("https://s3.amazonaws.com");
} else if (aws_endpoint.contains("us-west")) {
s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
} else if (aws_endpoint.contains("eu-west")) {
s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
} else if (aws_endpoint.contains("ap-")) {
s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
} else if (aws_endpoint.contains("sa-east-1")) {
s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
} else {
s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com");
}
} else {
s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build());
s3Client.setEndpoint(endpoint);
}
java.util.Date expiration = new java.util.Date();
long milliSeconds = expiration.getTime();
milliSeconds += 1000 * 60 * 1000; // Add 1 hour.
expiration.setTime(milliSeconds);
GeneratePresignedUrlRequest generatePresignedUrlRequest
= new GeneratePresignedUrlRequest(bucket, object);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
URL = ("Pre-Signed URL = " + url.toString());
StringSelection stringSelection = new StringSelection(url.toString());
} catch (Exception setACLpublic) {
}
return URL;
}