Skip to content

Commit

Permalink
Merge pull request #1656 from dalbani/patch-4
Browse files Browse the repository at this point in the history
MODE-2692 Return null MIME type from S3BinaryStore if it hasn't been detected yet
  • Loading branch information
Horia Chiorean committed Apr 28, 2017
2 parents d4958a2 + 4e9eb12 commit 0fb556c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -67,6 +67,11 @@ public class S3BinaryStore extends AbstractBinaryStore {
*/
protected static final String EXTRACTED_TEXT_KEY = "extracted-text";

/*
* Key for storing boolean which describes if a MIME type has been explicitly set
*/
protected static final String USER_MIME_TYPE_KEY = "user-mime-type";

/*
* Key for storing boolean which describes if object is unused
*/
Expand Down Expand Up @@ -140,7 +145,11 @@ protected String getStoredMimeType(BinaryValue binaryValue) throws BinaryStoreEx
try {
String key = binaryValue.getKey().toString();
ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, key);
return metadata.getContentType();
if (String.valueOf(true).equals(metadata.getUserMetadata().get(USER_MIME_TYPE_KEY))) {
return metadata.getContentType();
} else {
return null;
}
} catch (AmazonClientException e) {
throw new BinaryStoreException(e);
}
Expand All @@ -152,6 +161,7 @@ protected void storeMimeType(BinaryValue binaryValue, String mimeType) throws Bi
String key = binaryValue.getKey().toString();
ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, key);
metadata.setContentType(mimeType);
metadata.addUserMetadata(USER_MIME_TYPE_KEY, String.valueOf(true));

// Update the object in place
CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, key, bucketName, key);
Expand Down
Expand Up @@ -87,6 +87,7 @@ public void tearDown() {
public void testGetStoredMimeType() throws BinaryStoreException {
ObjectMetadata objMeta = new ObjectMetadata();
objMeta.setContentType(TEST_MIME);
objMeta.addUserMetadata(S3BinaryStore.USER_MIME_TYPE_KEY, String.valueOf(true));
expect(s3Client.getObjectMetadata(BUCKET, TEST_KEY)).andReturn(objMeta);

replayAll();
Expand Down

0 comments on commit 0fb556c

Please sign in to comment.