List of usage examples for com.amazonaws.services.s3.model GeneratePresignedUrlRequest GeneratePresignedUrlRequest
public GeneratePresignedUrlRequest(String bucketName, String key)
From source file:eu.crowdrec.flume.plugins.source.DirectIdomaarSource.java
License:Apache License
private BufferedReader createReaderFromUrl() throws IOException { if (url.startsWith("s3://")) { logger.info("Reading resource {} from Amazon S3.", url); AmazonS3 s3 = new AmazonS3Client(createAWSCreditentials()); AmazonS3URI amazonURI = new AmazonS3URI(url); GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(amazonURI.getBucket(), amazonURI.getKey());/* w w w .ja v a 2 s. com*/ URL httpUrl = s3.generatePresignedUrl(request); InputStream inp = httpUrl.openStream(); return new BufferedReader(new InputStreamReader(inp)); } throw new RuntimeException("Can only handle s3:// scheme. Cannot use URL " + url); }
From source file:hudson.plugins.ec2.EC2Cloud.java
License:Open Source License
/** * Computes the presigned URL for the given S3 resource. * * @param path/* w w w . ja v a 2s .c o m*/ * 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); }
From source file:io.konig.camel.aws.s3.DeleteObjectProducer.java
License:Apache License
private void createDownloadLink(AmazonS3 s3Client, Exchange exchange) { String bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class); if (ObjectHelper.isEmpty(bucketName)) { bucketName = getConfiguration().getBucketName(); }/* w ww . j av a 2 s. co m*/ if (bucketName == null) { throw new IllegalArgumentException("AWS S3 Bucket name header is missing."); } String key = exchange.getIn().getHeader(S3Constants.KEY, String.class); if (key == null) { throw new IllegalArgumentException("AWS S3 Key header is missing."); } Date expiration = new Date(); long milliSeconds = expiration.getTime(); Long expirationMillis = exchange.getIn().getHeader(S3Constants.DOWNLOAD_LINK_EXPIRATION, Long.class); if (expirationMillis != null) { milliSeconds += expirationMillis; } else { milliSeconds += 1000 * 60 * 60; // Default: Add 1 hour. } expiration.setTime(milliSeconds); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key); generatePresignedUrlRequest.setMethod(HttpMethod.GET); generatePresignedUrlRequest.setExpiration(expiration); URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest); Message message = getMessageForResponse(exchange); message.setHeader(S3Constants.DOWNLOAD_LINK, url.toString()); }
From source file:io.stallion.services.S3StorageService.java
License:Open Source License
public String getSignedDownloadUrl(String bucket, String fileKey) { GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, fileKey); req.setExpiration(Date.from(utcNow().plusMinutes(60).toInstant())); req.setMethod(HttpMethod.GET);//from w w w .ja v a 2 s . c o m return client.generatePresignedUrl(req).toString(); }
From source file:io.stallion.services.S3StorageService.java
License:Open Source License
public String getSignedUploadUrl(String bucket, String fileKey, String contentType, Map headers) { GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, fileKey); if (!empty(contentType)) { req.setContentType(contentType); }/*from ww w.j av a 2 s . co m*/ if (headers != null) { for (Object key : headers.keySet()) req.addRequestParameter(key.toString(), headers.get(key).toString()); } req.setExpiration(Date.from(utcNow().plusDays(2).toInstant())); req.setMethod(HttpMethod.PUT); return client.generatePresignedUrl(req).toString(); }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
@Override public F.Promise<Result> getDownload(String key, String name) { GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key); ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides(); responseHeaders.setContentDisposition("attachment; filename=" + name); generatePresignedUrlRequest.setResponseHeaders(responseHeaders); AmazonS3 amazonS3 = new AmazonS3Client(credentials); try {//from w ww . ja v a 2s.c om URL url = amazonS3.generatePresignedUrl(generatePresignedUrlRequest); return F.Promise.pure(redirect(url.toString())); } catch (AmazonClientException ace) { logAmazonClientException(ace); return F.Promise.pure(internalServerError(error.render())); } }
From source file:org.alanwilliamson.amazon.s3.GetUrl.java
License:Open Source License
@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);//from ww w.j a v a 2 s.c om 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; } }
From source file:org.apache.flink.cloudsort.io.aws.AwsCurlInput.java
License:Apache License
@Override public void open(String objectName) throws IOException { Preconditions.checkNotNull(bucket);//ww w . j av a2s. co m AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider()); java.util.Date expiration = new java.util.Date(); long msec = expiration.getTime(); msec += 1000 * 60 * 60; // Add 1 hour. expiration.setTime(msec); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket, objectName); generatePresignedUrlRequest.setMethod(HttpMethod.GET); generatePresignedUrlRequest.setContentType(CONTENT_TYPE); generatePresignedUrlRequest.setExpiration(expiration); String url = s3Client.generatePresignedUrl(generatePresignedUrlRequest).toExternalForm(); downloader = new ProcessBuilder("curl", "-s", "-X", "GET", "-H", "Content-Type: " + CONTENT_TYPE, url) .redirectError(Redirect.INHERIT).start(); }
From source file:org.apache.flink.cloudsort.io.aws.AwsCurlOutput.java
License:Apache License
@Override public Process open(String filename, String taskId) throws IOException { Preconditions.checkNotNull(bucket);//from w ww. jav a 2s .c om Preconditions.checkNotNull(prefix); Preconditions.checkNotNull(filename); Preconditions.checkNotNull(taskId); String objectName = prefix + taskId; AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider()); java.util.Date expiration = new java.util.Date(); long msec = expiration.getTime(); msec += 1000 * 60 * 60; // Add 1 hour. expiration.setTime(msec); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket, objectName); generatePresignedUrlRequest.setMethod(HttpMethod.PUT); generatePresignedUrlRequest.setContentType(CONTENT_TYPE); generatePresignedUrlRequest.setExpiration(expiration); String url = s3Client.generatePresignedUrl(generatePresignedUrlRequest).toExternalForm(); return new ProcessBuilder("curl", "-s", "--max-time", "60", "--retry", "1024", "-X", "PUT", "-H", "Content-Type: " + CONTENT_TYPE, "--data-binary", "@" + filename, url) .redirectError(Redirect.INHERIT).redirectOutput(Redirect.INHERIT).start(); }
From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.AmazonS3Uploader.java
License:Open Source License
/** * Returns a pre-signed URL for accessing an Amazon S3 resource. * /* w w w .ja v a 2s .co m*/ * @param bucketName * The bucket where the resource lies. * @param objectKey * The key object. * @return A pre-signed URL for accessing an Amazon S3 resource. */ public String generatePresignedURL(final String bucketName, final String objectKey) { final Date expiration = new Date(); expiration.setTime(System.currentTimeMillis() + ONE_DAY_IN_MILLIS); final GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey); generatePresignedUrlRequest.setMethod(HttpMethod.GET); // Default. generatePresignedUrlRequest.setExpiration(expiration); URL generatePresignedObjectURL = s3client.generatePresignedUrl(generatePresignedUrlRequest); if (logger.isLoggable(Level.FINEST)) { logger.finest("Zip uploaded. Limited signed URL: " + generatePresignedObjectURL); } return generatePresignedObjectURL.toString(); }