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

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

Introduction

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

Prototype

public void setContentType(String contentType) 

Source Link

Document

Sets the expected content-type of the request.

Usage

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);
    }/*w  ww.j a va2 s  . c om*/
    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.apache.flink.cloudsort.io.aws.AwsCurlInput.java

License:Apache License

@Override
public void open(String objectName) throws IOException {
    Preconditions.checkNotNull(bucket);//from w  w  w .  j a va2s. com

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

    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 w  w  .j av a  2s  . c o m

    request.setExpiration(new Date(System.currentTimeMillis() + DURATION));
    request.setContentType("application/octet-stream");

    return client.generatePresignedUrl(request);
}