mirror of https://github.com/apache/jclouds.git
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:
parent
4621176516
commit
2409ac1a37
|
@ -28,6 +28,7 @@ import org.jclouds.aws.s3.blobstore.strategy.MultipartUploadStrategy;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||||
|
import org.jclouds.io.ContentMetadata;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.PayloadSlicer;
|
import org.jclouds.io.PayloadSlicer;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -72,6 +73,7 @@ public class SequentialMultipartUploadStrategy implements MultipartUploadStrateg
|
||||||
@Override
|
@Override
|
||||||
public String execute(String container, Blob blob) {
|
public String execute(String container, Blob blob) {
|
||||||
String key = blob.getMetadata().getName();
|
String key = blob.getMetadata().getName();
|
||||||
|
ContentMetadata metadata = blob.getMetadata().getContentMetadata();
|
||||||
Payload payload = blob.getPayload();
|
Payload payload = blob.getPayload();
|
||||||
Long length = payload.getContentMetadata().getContentLength();
|
Long length = payload.getContentMetadata().getContentLength();
|
||||||
checkNotNull(length,
|
checkNotNull(length,
|
||||||
|
@ -79,7 +81,10 @@ public class SequentialMultipartUploadStrategy implements MultipartUploadStrateg
|
||||||
long chunkSize = algorithm.calculateChunkSize(length);
|
long chunkSize = algorithm.calculateChunkSize(length);
|
||||||
int partCount = algorithm.getParts();
|
int partCount = algorithm.getParts();
|
||||||
if (partCount > 0) {
|
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 {
|
try {
|
||||||
SortedMap<Integer, String> etags = Maps.newTreeMap();
|
SortedMap<Integer, String> etags = Maps.newTreeMap();
|
||||||
int part;
|
int part;
|
||||||
|
|
|
@ -34,6 +34,8 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.collect.ImmutableSet;
|
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.inject.Module;
|
||||||
import com.google.mockwebserver.MockResponse;
|
import com.google.mockwebserver.MockResponse;
|
||||||
import com.google.mockwebserver.MockWebServer;
|
import com.google.mockwebserver.MockWebServer;
|
||||||
|
@ -62,12 +64,17 @@ public class SequentialMultipartUploadStrategyMockTest {
|
||||||
partSize);
|
partSize);
|
||||||
|
|
||||||
try {
|
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 {
|
} finally {
|
||||||
|
|
||||||
RecordedRequest initiate = server.takeRequest();
|
RecordedRequest initiate = server.takeRequest();
|
||||||
assertEquals(initiate.getRequestLine(), "POST /container/foo?uploads HTTP/1.1");
|
assertEquals(initiate.getRequestLine(), "POST /container/foo?uploads HTTP/1.1");
|
||||||
assertEquals(initiate.getHeader("Content-Length"), "0");
|
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();
|
RecordedRequest part1 = server.takeRequest();
|
||||||
assertEquals(part1.getRequestLine(), "PUT /container/foo?partNumber=1&uploadId=upload-id HTTP/1.1");
|
assertEquals(part1.getRequestLine(), "PUT /container/foo?partNumber=1&uploadId=upload-id HTTP/1.1");
|
||||||
|
|
Loading…
Reference in New Issue