本文整理汇总了Java中com.amazonaws.services.s3.model.GeneratePresignedUrlRequest类的典型用法代码示例。如果您正苦于以下问题:Java GeneratePresignedUrlRequest类的具体用法?Java GeneratePresignedUrlRequest怎么用?Java GeneratePresignedUrlRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeneratePresignedUrlRequest类属于com.amazonaws.services.s3.model包,在下文中一共展示了GeneratePresignedUrlRequest类的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: getPreSignedUrl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入依赖的package包/类
@NotNull
@Override
public String getPreSignedUrl(@NotNull HttpMethod httpMethod, @NotNull String bucketName, @NotNull String objectKey, @NotNull Map<String, String> params) throws IOException {
try {
final Callable<String> resolver = () -> S3Util.withS3Client(params, client -> {
final GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, objectKey, httpMethod)
.withExpiration(new Date(System.currentTimeMillis() + getUrlLifetimeSec() * 1000));
return client.generatePresignedUrl(request).toString();
});
if (httpMethod == HttpMethod.GET) {
return TeamCityProperties.getBoolean(TEAMCITY_S3_PRESIGNURL_GET_CACHE_ENABLED)
? myGetLinksCache.get(getCacheIdentity(params, objectKey, bucketName), resolver)
: resolver.call();
} else {
return resolver.call();
}
} catch (Exception e) {
final AWSException awsException = new AWSException(e.getCause());
if (StringUtil.isNotEmpty(awsException.getDetails())) {
LOG.warn(awsException.getDetails());
}
final String err = "Failed to create " + httpMethod.name() + " pre-signed URL for [" + objectKey + "] in bucket [" + bucketName + "]";
LOG.infoAndDebugDetails(err, awsException);
throw new IOException(err + ": " + awsException.getMessage(), awsException);
}
}
开发者ID:JetBrains,项目名称:teamcity-s3-artifact-storage-plugin,代码行数:27,代码来源:S3PreSignedUrlProviderImpl.java
示例3: 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.");
}
示例4: generatePresignedUrl
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入依赖的package包/类
/**
* {@inheritDoc} <p/> <p> A mock implementation which generates a URL which reflects the given request. </p> <p> The URL is composed as such: </p> <p/>
* <pre>
* https://{s3BucketName}/{s3ObjectKey}?{queryParams}
* </pre>
* <p> Where {@code queryParams} is the URL encoded list of parameters given in the request. </p> <p> The query params include: </p> TODO: list the query
* params in the result.
*/
@Override
public URL generatePresignedUrl(GeneratePresignedUrlRequest generatePresignedUrlRequest, AmazonS3 s3)
{
String host = generatePresignedUrlRequest.getBucketName();
StringBuilder file = new StringBuilder();
file.append('/').append(generatePresignedUrlRequest.getKey());
file.append("?method=").append(generatePresignedUrlRequest.getMethod());
file.append("&expiration=").append(generatePresignedUrlRequest.getExpiration().getTime());
try
{
return new URL("https", host, file.toString());
}
catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
}
示例5: 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);
}
示例6: 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);
}
示例7: 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()));
}
示例8: 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();
}
}
示例9: generateObjectURL
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; //导入依赖的package包/类
@Override
public URL generateObjectURL(final String bucketName, final String fileName)
throws AmazonClientException, AmazonServiceException {
LOGGER.info("generateObjectURL invoked, bucketName: {}, fileName: {}", bucketName, fileName);
final GeneratePresignedUrlRequest presignedUrlReq = new GeneratePresignedUrlRequest(bucketName, fileName);
return s3client.generatePresignedUrl(presignedUrlReq);
}
示例10: 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));
}
示例11: 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));
}
示例12: 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);
}
示例13: 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;
}
}
示例14: 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;
}
示例15: 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;
}