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

resovles #1648 set content type multipart upload #2672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.internal.Mimetypes;

import java.io.File;
import java.io.Serializable;
import java.util.Date;

Expand Down Expand Up @@ -537,6 +539,39 @@ public InitiateMultipartUploadRequest withObjectMetadata(ObjectMetadata objectMe
return this;
}

/**
* Sets the additional information of content type about the new object being created.
* Sets content type in the object metadata. Creates object metadata if does not exist.
*
* @param file
* File that would be uploaded. Uses file extension to determine
* mimetype.
*/
public void setObjectMetadataContentTypeFromFile(File file) {
if (this.objectMetadata == null) {
this.objectMetadata = new ObjectMetadata();
}
this.objectMetadata.setContentType(Mimetypes.getInstance().getMimetype(file));
}

/**
* Sets the additional information of content type about the new object being created.
* Sets content type in the object metadata. Creates object metadata if does not exist.
* <p>
* Returns this updated InitiateMultipartUploadRequest object so that
* additional method calls can be chained together.
*
* @param file
* File that would be uploaded. Uses file extension to determine
* mimetype.
*
* @return This updated InitiateMultipartUploadRequest object.
*/
public InitiateMultipartUploadRequest withObjectMetadataContentTypeFromFile(File file) {
setObjectMetadataContentTypeFromFile(file);
return this;
}

/**
* Sets the optional redirect location for the new object.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.amazonaws.services.s3.model;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

import java.io.File;

/**
* Test Model InitiateMultipartUploadRequest
*/
public class InitiateMultipartUploadRequestTest {

/**
* Test setting the content type of the metadata for the multipart upload request
*/
@Test
public void testWithObjectMetadataContentTypeFromFile(){
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest("bucketName", "key", new ObjectMetadata());
File file = new File("textFile.txt");
request = request.withObjectMetadataContentTypeFromFile(file);
assertEquals("text/plain", request.getObjectMetadata().getContentType());
}

/**
* Test setting the content type of the metadata for the multipart upload request
* Creates the metadata object if it does not exist
*/
@Test
public void testWithObjectMetadataContentTypeFromFileCreatesMetadata(){
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest("bucketName", "key");
File file = new File("textFile.txt");
request = request.withObjectMetadataContentTypeFromFile(file);
assertEquals("text/plain", request.getObjectMetadata().getContentType());
}
}