mirror of https://github.com/apache/jclouds.git
Added futher implementation for content disposition
This commit is contained in:
parent
5d8f3bdb37
commit
4c2ff1ea63
|
@ -530,6 +530,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
blob.getMetadata().setSize(payload.getContentLength());
|
||||
blob.getMetadata().setContentMD5(payload.getContentMD5());
|
||||
blob.getMetadata().setContentType(payload.getContentType());
|
||||
blob.getMetadata().setContentDisposition(payload.getContentDisposition());
|
||||
|
||||
String eTag = CryptoStreams.hex(payload.getContentMD5());
|
||||
blob.getMetadata().setETag(eTag);
|
||||
|
@ -542,6 +543,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
Collections.singleton(payload.getContentLength() + ""));
|
||||
blob.getAllHeaders().replaceValues("Content-MD5",
|
||||
Collections.singleton(CryptoStreams.base64(payload.getContentMD5())));
|
||||
//TODO maybe i should change here content-disposition
|
||||
blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata()));
|
||||
return blob;
|
||||
}
|
||||
|
|
|
@ -41,4 +41,12 @@ public interface BlobMetadata extends StorageMetadata {
|
|||
|
||||
byte[] getContentMD5();
|
||||
|
||||
/**
|
||||
* Content-Disposition to set for the blob.
|
||||
* <p/>
|
||||
* <b>Attention</b>: Not all provider support it!
|
||||
* @return
|
||||
*/
|
||||
String getContentDisposition();
|
||||
|
||||
}
|
|
@ -43,4 +43,6 @@ public interface MutableBlobMetadata extends BlobMetadata, MutableStorageMetadat
|
|||
|
||||
void setContentMD5(@Nullable byte[] md5);
|
||||
|
||||
String setContentDisposition(@Nullable String contentDisposition);
|
||||
|
||||
}
|
|
@ -144,6 +144,7 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
|||
super(delegate);
|
||||
this.metadata = metadata;
|
||||
setContentType(metadata.getContentType());
|
||||
setContentDisposition(metadata.getContentDisposition());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,6 +153,11 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
|||
metadata.setContentType(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentDisposition(String contentDisposition) {
|
||||
super.setContentDisposition(contentDisposition);
|
||||
metadata.setContentDisposition(contentDisposition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -109,11 +109,12 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testBigFileGets() throws InterruptedException, IOException {
|
||||
final String expectedContentDisposition = "attachment; filename=constit.txt";
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
String key = "constitution.txt";
|
||||
|
||||
uploadConstitution(containerName, key);
|
||||
uploadConstitution(containerName, key, expectedContentDisposition);
|
||||
Map<Integer, Future<?>> responses = Maps.newHashMap();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
|
@ -124,6 +125,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
public Void apply(Blob from) {
|
||||
try {
|
||||
assertEquals(CryptoStreams.md5(from.getPayload()), oneHundredOneConstitutionsMD5);
|
||||
checkContentDispostion(from, expectedContentDisposition);
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
|
@ -142,14 +144,26 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
}
|
||||
|
||||
private void uploadConstitution(String containerName, String key) throws IOException {
|
||||
private void uploadConstitution(String containerName, String key, String contentDisposition) throws IOException {
|
||||
Blob sourceObject = context.getBlobStore().newBlob(key);
|
||||
sourceObject.getMetadata().setContentType("text/plain");
|
||||
sourceObject.getMetadata().setContentMD5(oneHundredOneConstitutionsMD5);
|
||||
sourceObject.getMetadata().setContentDisposition(contentDisposition);
|
||||
sourceObject.setPayload(oneHundredOneConstitutions.getInput());
|
||||
context.getBlobStore().putBlob(containerName, sourceObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods for checking Content-Disposition. In this way, in implementations
|
||||
* that do not support the new field, it is easy to override with empty,
|
||||
* and allow the rest of the test to work.
|
||||
* @param blob
|
||||
* @param expected
|
||||
*/
|
||||
protected void checkContentDispostion(Blob blob, String expected){
|
||||
assertEquals(blob.getPayload().getContentDisposition(), expected);
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testGetIfModifiedSince() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
|
|
|
@ -227,6 +227,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
|||
assertEquals(client.postJson("", "foo").trim(), "{\"key\":\"foo\"}POST");
|
||||
}
|
||||
|
||||
@Test(invocationCount = 5, timeOut = 5000)
|
||||
public void testPostContentDisposition() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||
TimeoutException {
|
||||
assertEquals(client.postWithContentDisposition("", "attachment; filename=photo.jpg", "foo").trim(), "content-disposition:photo.jpg");
|
||||
|
|
Loading…
Reference in New Issue