Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support presigned PUT requests with content-type #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/com/amazonaws/services/s3/AmazonS3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public AmazonS3Client(AWSCredentials awsCredentials, ClientConfiguration clientC
* Constructs a new Amazon S3 client using the specified AWS credentials
* provider to access Amazon S3.
*
* @param awsCredentialsProvider
* @param credentialsProvider
* The AWS credentials provider which will provide credentials
* to authenticate requests with AWS services.
*/
Expand All @@ -278,7 +278,7 @@ public AmazonS3Client(AWSCredentialsProvider credentialsProvider) {
* Constructs a new Amazon S3 client using the specified AWS credentials and
* client configuration to access Amazon S3.
*
* @param awsCredentialsProvider
* @param credentialsProvider
* The AWS credentials provider which will provide credentials
* to authenticate requests with AWS services.
* @param clientConfiguration
Expand Down Expand Up @@ -1819,12 +1819,18 @@ public URL generatePresignedUrl(GeneratePresignedUrlRequest generatePresignedUrl
new Date(System.currentTimeMillis() + 1000 * 60 * 15));
}


HttpMethodName httpMethod = HttpMethodName.valueOf(generatePresignedUrlRequest.getMethod().toString());
Request<GeneratePresignedUrlRequest> request = createRequest(bucketName, key, generatePresignedUrlRequest, httpMethod);
for (Entry<String, String> entry : generatePresignedUrlRequest.getRequestParameters().entrySet()) {
request.addParameter(entry.getKey(), entry.getValue());
}

if (generatePresignedUrlRequest.getContentType() != null) {
request.addHeader("content-type", generatePresignedUrlRequest.getContentType());
}


addResponseHeaderParameters(request, generatePresignedUrlRequest.getResponseHeaders());

presignRequest(request, generatePresignedUrlRequest.getMethod(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class GeneratePresignedUrlRequest extends AmazonWebServiceRequest {
/** The key of the object involved in this request */
private String key;

/** The optional content-type (for PUT and POST) */
private String contentType;

/**
* An optional expiration date at which point the generated pre-signed URL
* will no longer be accepted by Amazon S3. If not specified, a default
Expand Down Expand Up @@ -324,4 +327,41 @@ public GeneratePresignedUrlRequest withResponseHeaders(ResponseHeaderOverrides r
setResponseHeaders(responseHeaders);
return this;
}

/**
* Gets the expected content-type of the request. The content-type is included in
* the signature.
*
* @return The expected content-type
*/
public String getContentType() {
return contentType;
}

/**
* Sets the expected content-type of the request. The content-type is included in
* the signature.
* @param contentType
* The expected content-type
*/
public void setContentType(String contentType) {
this.contentType = contentType;
}

/**
* Sets the expected content-type of the request and returns
* this object, for method chaining.
*
* @param contentType
* The expected content-type
*
*
* @return This {@link GeneratePresignedUrlRequest} for method chaining.
*/
public GeneratePresignedUrlRequest withContentType(String contentType) {
setContentType(contentType);
return this;
}


}