当前位置: 首页>>代码示例>>Java>>正文


Java GeneratePresignedUrlRequest类代码示例

本文整理汇总了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;
}
 
开发者ID:qaprosoft,项目名称:carina,代码行数:23,代码来源:AmazonS3Manager.java

示例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.");
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:25,代码来源:SbpS3UrlGenerator.java

示例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);
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:26,代码来源:MockS3OperationsImpl.java

示例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); 
  }
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:9,代码来源:ContentHelper.java

示例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);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:9,代码来源:AmazonS3Client.java

示例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()));
}
 
开发者ID:EMCECS,项目名称:ecs-samples,代码行数:31,代码来源:_07_PresignedURL.java

示例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();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:16,代码来源:S3DaoImpl.java

示例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);
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:8,代码来源:AwsS3IamServiceImpl.java

示例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));
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:11,代码来源:S3Storage.java

示例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));
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:12,代码来源:S3Storage.java

示例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);
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:15,代码来源:EC2Cloud.java

示例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;
	}
 }
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:40,代码来源:GetUrl.java

示例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;
}
 
开发者ID:cs553-cloud-computing,项目名称:amazon-cloudengine,代码行数:37,代码来源:S3Service.java

示例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;
}
 
开发者ID:awslabs,项目名称:amazon-kinesis-aggregators,代码行数:30,代码来源:ConfigFileUtils.java


注:本文中的com.amazonaws.services.s3.model.GeneratePresignedUrlRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。