Example usage for com.amazonaws.services.s3.model GeneratePresignedUrlRequest addRequestParameter

List of usage examples for com.amazonaws.services.s3.model GeneratePresignedUrlRequest addRequestParameter

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model GeneratePresignedUrlRequest addRequestParameter.

Prototype

public void addRequestParameter(String key, String value) 

Source Link

Document

Adds an additional request parameter to be included in the pre-signed URL.

Usage

From source file:edu.upenn.library.fcrepo.connector.annex.S3AnnexResolverFactory.java

License:Apache License

public URI getObjectURI(String annexId, Map<String, String> remoteResponseHeaderHints) {
    GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, annexId);
    request.addRequestParameter(ResponseHeaderOverrides.RESPONSE_HEADER_CONTENT_TYPE,
            remoteResponseHeaderHints.get(Headers.CONTENT_TYPE));
    request.addRequestParameter(ResponseHeaderOverrides.RESPONSE_HEADER_CONTENT_DISPOSITION,
            remoteResponseHeaderHints.get(Headers.CONTENT_DISPOSITION));
    try {/*from  ww w.  j a v a  2  s .  c om*/
        return conn.generatePresignedUrl(request).toURI();
    } catch (URISyntaxException ex) {
        throw null;
    }
}

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);
    }//ww  w  .ja  v  a  2  s  .c o  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:org.icgc.dcc.storage.server.repository.s3.S3URLGenerator.java

License:Open Source License

@Override
public String getUploadPartUrl(String bucketName, ObjectKey objectKey, String uploadId, Part part,
        Date expiration) {/*from  w w  w. j  a  va2  s .  c  om*/
    GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, objectKey.getKey(),
            HttpMethod.PUT);
    req.setExpiration(expiration);

    req.addRequestParameter("partNumber", String.valueOf(part.getPartNumber()));
    req.addRequestParameter("uploadId", uploadId);

    return s3Client.generatePresignedUrl(req).toString();
}

From source file:org.nuxeo.ecm.core.storage.sql.S3BinaryManager.java

License:Apache License

@Override
protected URI getRemoteUri(String digest, ManagedBlob blob, HttpServletRequest servletRequest)
        throws IOException {
    String key = bucketNamePrefix + digest;
    Date expiration = new Date();
    expiration.setTime(expiration.getTime() + directDownloadExpire * 1000);
    GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.GET);
    request.addRequestParameter("response-content-type", getContentTypeHeader(blob));
    request.addRequestParameter("response-content-disposition", getContentDispositionHeader(blob, null));
    request.setExpiration(expiration);/*from  w  w  w.j  ava 2s .  c o  m*/
    URL url = amazonS3.generatePresignedUrl(request);
    try {
        return url.toURI();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
}

From source file:org.nuxeo.s3utils.S3HandlerImpl.java

License:Apache License

@Override
public String buildPresignedUrl(String inBucket, String inKey, int durationInSeconds, String contentType,
        String contentDisposition) throws NuxeoException {

    if (StringUtils.isBlank(inBucket)) {
        inBucket = currentBucket;/*from w w w.  j  a v  a  2 s .  c  o m*/
    }
    if (StringUtils.isBlank(inBucket)) {
        throw new NuxeoException("No bucket provided");
    }

    if (durationInSeconds <= 0) {
        durationInSeconds = signedUrlDuration;
    }
    if (durationInSeconds <= 0) {
        throw new IllegalArgumentException("duration of " + durationInSeconds + " is invalid.");
    }

    Date expiration = new Date();
    expiration.setTime(expiration.getTime() + (durationInSeconds * 1000));

    GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(currentBucket, inKey, HttpMethod.GET);

    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 NuxeoException(e);
    }

}

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>//from w w  w  . j a  v a 2  s. co m
 * 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);
    }

}