Preserve blob metadata for AWS-S3 MPU

Specifically preserve content-type and content-disposition for
multi-part uploads.

Fixes JCLOUDS-204
This commit is contained in:
Diwaker Gupta 2013-07-24 11:50:39 -07:00 committed by Andrew Gaul
parent 4621176516
commit 2409ac1a37
2 changed files with 14 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import org.jclouds.aws.s3.blobstore.strategy.MultipartUploadStrategy;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.io.ContentMetadata;
import org.jclouds.io.Payload;
import org.jclouds.io.PayloadSlicer;
import org.jclouds.logging.Logger;
@ -72,6 +73,7 @@ public class SequentialMultipartUploadStrategy implements MultipartUploadStrateg
@Override
public String execute(String container, Blob blob) {
String key = blob.getMetadata().getName();
ContentMetadata metadata = blob.getMetadata().getContentMetadata();
Payload payload = blob.getPayload();
Long length = payload.getContentMetadata().getContentLength();
checkNotNull(length,
@ -79,7 +81,10 @@ public class SequentialMultipartUploadStrategy implements MultipartUploadStrateg
long chunkSize = algorithm.calculateChunkSize(length);
int partCount = algorithm.getParts();
if (partCount > 0) {
String uploadId = client.initiateMultipartUpload(container, ObjectMetadataBuilder.create().key(key).build());
ObjectMetadataBuilder builder = ObjectMetadataBuilder.create().key(key)
.contentType(metadata.getContentType())
.contentDisposition(metadata.getContentDisposition());
String uploadId = client.initiateMultipartUpload(container, builder.build());
try {
SortedMap<Integer, String> etags = Maps.newTreeMap();
int part;

View File

@ -34,6 +34,8 @@ import org.testng.annotations.Test;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;
import com.google.inject.Module;
import com.google.mockwebserver.MockResponse;
import com.google.mockwebserver.MockWebServer;
@ -62,12 +64,17 @@ public class SequentialMultipartUploadStrategyMockTest {
partSize);
try {
assertEquals(api.execute("container", new BlobBuilderImpl().name("foo").payload(bytes).build()), "fff");
assertEquals(api.execute("container", new BlobBuilderImpl().name("foo").payload(bytes)
.contentDisposition("inline; filename=foo.mp4")
.contentType(MediaType.MP4_VIDEO.toString())
.build()), "fff");
} finally {
RecordedRequest initiate = server.takeRequest();
assertEquals(initiate.getRequestLine(), "POST /container/foo?uploads HTTP/1.1");
assertEquals(initiate.getHeader("Content-Length"), "0");
assertEquals(initiate.getHeader(HttpHeaders.CONTENT_TYPE), MediaType.MP4_VIDEO.toString());
assertEquals(initiate.getHeader(HttpHeaders.CONTENT_DISPOSITION), "inline; filename=foo.mp4");
RecordedRequest part1 = server.takeRequest();
assertEquals(part1.getRequestLine(), "PUT /container/foo?partNumber=1&uploadId=upload-id HTTP/1.1");