Skip to content

Commit d316021

Browse files
authored
Merge pull request #7 from wizpanda/content-type-fix
Fixed setting the content-type while uploading a file
2 parents b00d57e + ddd6f47 commit d316021

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/groovy/com/wizpanda/file/api/AmazonS3PermanentURLApi.groovy

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import groovy.util.logging.Slf4j
55
import org.jclouds.aws.s3.blobstore.options.AWSS3PutObjectOptions
66
import org.jclouds.s3.domain.S3Object
77
import org.jclouds.s3.domain.internal.MutableObjectMetadataImpl
8-
import org.jclouds.s3.domain.internal.S3ObjectImpl
98

109
@Slf4j
1110
class AmazonS3PermanentURLApi extends AmazonS3Api {
@@ -21,14 +20,18 @@ class AmazonS3PermanentURLApi extends AmazonS3Api {
2120
String fileName = getFileName(this.rawFile)
2221
String containerName = getContainerName()
2322

24-
MutableObjectMetadataImpl mutableObjectMetadata = new MutableObjectMetadataImpl()
23+
S3Object s3Object = client.newS3Object()
24+
s3Object.setPayload(this.rawFile)
25+
26+
MutableObjectMetadataImpl mutableObjectMetadata = s3Object.getMetadata()
2527
mutableObjectMetadata.setKey(fileName)
2628
setCacheControl(mutableObjectMetadata)
29+
/**
30+
* Always set the content-type after setting the payload so that it does not get overridden.
31+
* https://groups.google.com/d/msg/jclouds/FMuEbPo9M_k/kaXCKkuOKdMJ
32+
*/
2733
setContentType(mutableObjectMetadata)
2834

29-
S3Object s3Object = new S3ObjectImpl(mutableObjectMetadata)
30-
s3Object.setPayload(this.rawFile)
31-
3235
AWSS3PutObjectOptions fileOptions = new AWSS3PutObjectOptions()
3336
setAccessPolicy(fileOptions)
3437

0 commit comments

Comments
 (0)