List of usage examples for com.amazonaws.services.s3.model GeneratePresignedUrlRequest setExpiration
public void setExpiration(Date expiration)
From source file:org.nuxeo.sheridan.S3TempSignedURLBuilder.java
License:Open Source License
/** * Return an url as string. This url is a temporary signed url giving access to the object for * <code>expireInSeconds</expireInSeconds> seconds. After this time, the object cannot be accessed anymore with this URL. * <p>//w w w .ja v a 2 s .com * Some default values apply: * <p> * <ul> * <li>If <code>bucket</code> is empty (null, "", " ", ....), the bucket defined in the configuration is used.</li> * <li>If <code>expireInSeconds</code> is less than 1, the default * <code>S3TempSignedURLBuilder.DEFAULT_EXPIRE</code> is used</li> <li><code>contentType</code> and * <code>contentDisposition</code> can be null or "", but it is recommended to set them to make sure the is no * ambiguity when the URL is used (a key without a file extension for example)</li> </ul> * <p> * * @param bucket * @param objectKey * @param expireInSeconds * @param contentType * @param contentDisposition * @return the temporary signed Url * @throws IOException * @since 7.10 */ public String build(String bucket, String objectKey, int expireInSeconds, String contentType, String contentDisposition) throws IOException { if (StringUtils.isBlank(bucket)) { bucket = awsBucket; } if (StringUtils.isBlank(bucket)) { throw new NuxeoException( "No bucket provided, and configuration key " + CONF_KEY_NAME_BUCKET + " is missing."); } Date expiration = new Date(); if (expireInSeconds < 1) { expireInSeconds = DEFAULT_EXPIRE; } expiration.setTime(expiration.getTime() + (expireInSeconds * 1000)); GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, objectKey, HttpMethod.GET); // Do we need these? if (StringUtils.isNotBlank(contentType)) { request.addRequestParameter("response-content-type", contentType); } if (StringUtils.isNotBlank(contentDisposition)) { request.addRequestParameter("response-content-disposition", contentDisposition); } request.setExpiration(expiration); URL url = s3.generatePresignedUrl(request); try { URI uri = url.toURI(); return uri.toString(); } catch (URISyntaxException e) { throw new IOException(e); } }
From source file:org.restcomm.connect.commons.amazonS3.S3AccessTool.java
License:Open Source License
public URI getPublicUrl(String fileName) throws URISyntaxException { if (s3client == null) { s3client = getS3client();/*from w ww. j av a 2s . c om*/ } Date date = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.MINUTE, minutesToRetainPublicUrl); if (logger.isInfoEnabled()) { final String msg = String.format("Prepared amazon s3 public url valid for %s minutes for recording: %s", minutesToRetainPublicUrl, fileName); logger.info(msg); } date = cal.getTime(); String bucket = bucketName; if (folder != null && !folder.isEmpty()) { bucket = bucket.concat("/").concat(folder); } GeneratePresignedUrlRequest generatePresignedUrlRequestGET = new GeneratePresignedUrlRequest(bucket, fileName); generatePresignedUrlRequestGET.setMethod(HttpMethod.GET); generatePresignedUrlRequestGET.setExpiration(date); return s3client.generatePresignedUrl(generatePresignedUrlRequestGET).toURI(); }
From source file:org.whispersystems.textsecuregcm.s3.UrlSigner.java
License:Open Source License
public URL getPreSignedUrl(long attachmentId, HttpMethod method) { AmazonS3 client = new AmazonS3Client(credentials); GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, String.valueOf(attachmentId), method);//w w w . ja v a 2 s . com request.setExpiration(new Date(System.currentTimeMillis() + DURATION)); request.setContentType("application/octet-stream"); client.setS3ClientOptions(S3ClientOptions.builder().setAccelerateModeEnabled(true).build()); return client.generatePresignedUrl(request); }
From source file:org.whispersystems.textsecuregcm.util.UrlSigner.java
License:Open Source License
public URL getPreSignedUrl(long attachmentId, HttpMethod method) { AmazonS3 client = new AmazonS3Client(credentials); GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, String.valueOf(attachmentId), method);/*from w ww. j a v a 2 s . co m*/ request.setExpiration(new Date(System.currentTimeMillis() + DURATION)); request.setContentType("application/octet-stream"); return client.generatePresignedUrl(request); }